您的位置:首页 > 编程语言 > C语言/C++

C/C++ ifstream之eof()

2016-05-11 09:49 429 查看
参考来自:http://blog.csdn.net/rebel_321/article/details/4927464

程序实测可用:

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

string str;

ifstream fin("D:\\1.txt"/*, ios::binary*/);

if (fin.peek() == EOF)

{

cout << "file is empty." << endl;

return 0;

}

while (!fin.eof())

{

fin >> str;

cout << str<<' ' ;

}

system("pause");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: