用CFILE读文件怎么知道是否到了最后?
如:
CFile file("c:\\a.txt",modeRead);
char *str=new char[10000000]; //可以设置这么大的缓冲以提高速度吗?
file.Read(str,sizeof(str)); //怎么让它不断读直到最后?

解决方案 »

  1.   

    while(file.Read(str,sizeof(str)))
    {
    ...
    }
      

  2.   

    (1)缓冲区设置那么大没有用处
    (2)
    CString rtnValue;
    char ch;
    while (!feof(fp)) {
    rtnValue = rtnValue + ch;
    ch = fgetc(fp);
    }
      

  3.   

    CStdioFile file;
    CString strLine;
    while(file.ReadString(strLine))
    {
    //add you code;
    }
      

  4.   

    CStdioFile file; CStdioFile继承了Cfile 
    CString strLine;
    while(file.ReadString(strLine))
    {
    //add you code;
    }
      

  5.   

    CFile file;
    if(file.GetPosition()==file.Getlength())
      

  6.   

    Read()的返回值为读取字节的数目如果返回0或小于0就说明到了文件尾部
    ReadString()的返回值为布尔值,如果返回假就说明到了文件尾部
    你自己找一个适合的用吧
      

  7.   

    //可以设置这么大的缓冲以提高速度吗?
    如果仅仅是将文件内容读入内存的话,缓冲不易太大,一般应小于64k
    如4k,8k,32k等等,最好为4的倍数,windows处理32位最快//怎么让它不断读直到最后?
    CFile file("c:\\a.txt",modeRead);
    char *str=new char[4096]; 
    int nRet;
    nRet = file.Read(str,sizeof(str)); 
    while (nRet)
    {
       nRet = file.Read(str,sizeof(str)); 
    }