所以我试图利用 istringstream 来解析一个文本文件。这个想法是按空格分解每一行并基于子字符串做一些事情。该代码工作正常,除了两件事,它对每一行的最后一个子字符串进行双重计算,并且在完成文件读取时会出现错误。我以前没有使用过 sstream,所以任何见解都会有所帮助。
file.getline(str,80);
while(!file.eof())
{
cout<<str<<endl;
istringstream iss(str);
while (iss)
{
iss >> sstr;
cout << "Substring: " <<sstr << endl;
}
file.getline(str,80);
}