我在vc中使用这样的循环从文件中读取记录fstream ftemp;
char buffer[80];
...ftemp的构造函数while(!fTemp.eof())
{
fTemp.getline(buffer,80);
}
但奇怪的问题出现了,在我的程序还没有读完这个文件的时候,eof()就返回了一个非0数值,然后循环跳出。这让我很恼火,也不知道怎么办?
我使用的是vc6.0没有安装补丁。
这是怎么回事?

解决方案 »

  1.   

    getline返回一行,所以buffer不能太小
      

  2.   

    好象不是这问题;你#include <iostream.h>、#include <fstream.h>吗?
      

  3.   

    三种情况
    At end of file. 
    After the function extracts an element that compares equal to delim, in which case the element is neither put back nor appended to the controlled sequence. 
    After the function extracts str.max_size elements, in which case the function calls setstate(ios_base::failbit). 
      

  4.   

    我使用的是
    #include <fstream.h>
      

  5.   

    inline int  ios::eof() const { return state & eofbit; }eofbit=1;
    你看看你的文件中间是否有0x01;
    这是它的bug;