// entrada是我打开的fstream
if (entrada.is_open())
{
while (!entrada.eof())
{
char palabra[1024];
entrada >> palabra;
if(entrada.eof())break;
cout << palabra << endl;
}
entrada.close();
}
程序显示文本并且没有完成while的循环,没有达到.eof
答案 0 :(得分:1)
将循环更改为:
char palabra[1024];
while (entrada >> palabra )
{
cout << palabra << endl;
}
请参阅Why is iostream::eof inside a loop condition considered wrong?