ifstream& operator>>函数无法获取空行
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string str;
ifstream fin("c:\\1.txt"/*, ios::binary*/);
if(!fin.is_open())
{
cout<<"打开失败\r\n";
return 0;
}
if (fin.peek() == EOF)
{
cout << "file is empty."<<endl;
return 0;
}
int count=0;
while (!fin.eof())
{
fin >> str;
cout << str<<endl;
count++;
}
system("pause");
return 0;
}
peek函数才能够做到防止空文件的出现