0
我想創建一個while循環,只要從文件中取出的字符串不是空的就運行。我需要用空格分隔字符串並保存信息以供將來使用,所以我將子字符串放入數組中,然後將其從實際數組中移除。但是,當我運行該程序時,我不斷收到錯誤消息,或者只是打印出空白區域。 I added a picture of the file I'm using and of the error message I'm getting子串和擦除
fstream myfile;
string line;
string info[10000];
int i=0, pos;
myfile.open("bfine_project1_input.txt");
//Check
if (myfile.fail()){
cerr << "Error opening file" << endl;
exit(1);
}
if (myfile.is_open()){
while (getline (myfile,line)){
while(line.size() !=0){
pos = line.find(" ");
info[i]= line.substr(0,pos);
i++;
cout << info[i] << endl;
//line.erase(0, pos);
}
}
}
是info' vector'?如果是這樣,它的大小適當嗎? – GWW
info是一個數組 – cdecaro
如何聲明信息?我如何申報?我在哪裏分配?你收到什麼錯誤信息?爲什麼SO需要[mcve]? –