我知道這裏有很多類似標題的問題,但似乎沒有人爲我工作。 我有這樣的txt文件的:將.txt文件存儲爲char * 2d向量C++
tree pine
color blue
food pizza
,我想存儲在一個char * 2D矢量的項目,如
vector<vector<char*>> data;
..
..
data[0][0] = tree
data[0][1] = pine
data[1][1] = blue
ecc
這是代碼:
// parse configuration file
bool Configuration::fileParser(char* filename)
{
vector<vector<char*>> data;
fstream fin("data/setup.txt");
string line;
while (fin && getline(fin, line))
{
vector<char*> confLine;
char* word = NULL;
stringstream ss(line);
while (ss && ss >> word)
{
confLine.push_back(word);
}
data.push_back(confLine);
}
storeData(data);
return 0;
}
但是,當我運行代碼引發異常。
Exception thrown: write access violation.
我該如何解決這個問題? 謝謝
「我該如何解決這個問題?」首先使用'std :: string'。 – DimChtz
你使用什麼編譯器? – Aan
在哪一行/哪個函數是拋出的異常? 'storeData'如何實現?我們不知道您項目的背景,因此您必須儘可能提供完整的信息。 – meowgoesthedog