好的,我在这里看到了答案,但我仍然不明白我需要做什么。我试图从文件中读取内容,但我用.eof()得到了意想不到的结果,我对此感到沮丧!我删除了我正在为我正在做的项目实际做的事情,但希望我的代码足以提供帮助。我在函数中有一堆类似的while循环,因为我正在尝试解析文件中的数据并将数据分配给正确的数据结构。它似乎工作时它也需要我正在测试的一个文件工作,而另一个说它到达文件的末尾,而实际上它还有一个数据要读取。我不知道发生了什么事。提前谢谢你的帮助!
void ReadStuff(ifstream &theFile)
{
while (!theFile.eof())
{
string line;
getline(theFile, line);
istringstream read(line);
string lineSect;
while (!read.eof())
{
read >> lineSect;
if (read.eof())
{
break;
}
//Reading stuff for this line
}
//Reading more stuff from a file until all data for all labels is read
}
}