c++ 文件结束判断 转载 - C++ - 关于ifstream/fstream流 判断文件是否结束eof()的问题

出处:http://blog.csdn.net/shuilan0066/article/details/4669451

1、

ifstream in("config.txt", ios::in);
if (!in)
{
  cerr << "open file failed!";  
  exit(-1);  
}

while(in.peek()!=EOF)
{
    //do something
}

2、

ifstream in("config.txt", ios::in);
if (!in)
{
  cerr << "open file failed!";  
  exit(-1);  
}
do
{
    //do something
}while(!in.eof())

  

出处:http://blog.csdn.net/shuilan0066/article/details/4669451

1、

ifstream in("config.txt", ios::in);
if (!in)
{
  cerr << "open file failed!";  
  exit(-1);  
}

while(in.peek()!=EOF)
{
    //do something
}

2、

ifstream in("config.txt", ios::in);
if (!in)
{
  cerr << "open file failed!";  
  exit(-1);  
}
do
{
    //do something
}while(!in.eof())

  

猜你喜欢

转载自www.cnblogs.com/quehualin/p/9140527.html