文件操作里怎么判断到文件末尾了?

解决方案 »

  1.   

    CFile的Read方法返回一个值,是读取的字节数,如果那个数为零,那么就是到达文件末尾了。
    Ex:
    UINT nBytesRead;
    Do
    {
      nBytesRead = srcfile.Read( pbuf, 100 );
      destfile.Write(pbuf,nBytesRead);
    }
    while(nBytesRead>0)
    这段代码用来把一个文件的内容拷到另外一个文件里
      

  2.   

    bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ; 
    // Check for end of file. 
    if (bResult &&  nBytesRead == 0, ) 

        // we're at the end of the file 

    msdn 中例子
      

  3.   

    bResult、hFile、inBuffer、nBytesToRead、nBytesRead该怎么声明啊?在哪声明?
    我加了个#include <afx.h>,只认出了ReadFile
      

  4.   

    BOOL bResult;
    HANDLE hFile;
    char inBuffer[BUFSIZE];
    int nBytesToRead, nBytesRead;你的是控制台程序吗?
      

  5.   

    用CFile类,有GetPosition()
    把返回值与GetLength()比较,就能知道是否到文件末尾了。
      

  6.   

    So simple !
    I agree with the above story,
    using fiof