带有eof()函数的文件结尾 [英] end of file with eof() function
本文介绍了带有eof()函数的文件结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜。我正在使用eof()函数,但似乎它不起作用。我写了
fstream f(test.txt);
while(!f.eof())
cout<< 1;
并且在我的文件中我写了sara
但程序没有完成并进入无限循环。为什么?
请帮帮我
谢谢
hi. i am using the eof() function but seems it does'nt work. i write
fstream f("test.txt");
while (!f.eof())
cout << "1";
and in my file i wrote "sara"
but the program doesn't finish and enters in the infinite loop . why?
please help me
thanks
推荐答案
引用:
但程序没有完成并进入无限循环。为什么?
but the program doesn't finish and enters in the infinite loop . why?
因为你没有从文件中读取。
Because you are not reading from the file.
正如CPallini所解释的那样,你没有读取文件。使用下面的示例代码进行阅读
As explained by CPallini you are not reading the file. Use below sample code for reading
fstream f( "test.txt", ios::in );
while( !inf.eof() ) {
cout << f.get() << "\n";
}
这篇关于带有eof()函数的文件结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文