我无法让 istringstream 在下面显示的 while 循环中继续。数据文件也如下所示。我使用输入文件中的 getline 来获取第一行并将其放入 istringstream lineStream 中。它通过一次while循环,然后读取第二行并返回到循环的开头并退出而不是继续循环。我不知道为什么,如果有人可以提供帮助,我将不胜感激。编辑:我有这个 while 循环条件的原因是因为文件可能包含错误数据行。因此,我想确保我正在读取的行在数据文件中具有如下所示的正确格式。
while(lineStream >> id >> safety){//keeps scanning in xsections until there is no more xsection IDs
while(lineStream >> concname){//scan in name of xsection
xname = xname + " " +concname;
}
getline(InputFile, inputline);//go to next xsection line
if(InputFile.good()){
//make inputline into istringstream
istringstream lineStream(inputline);
if(lineStream.fail()){
return false;
}
}
}
数据文件
4 0.2 speedway and mountain
7 0.4 mountain and lee
6 0.5 mountain and santa