CStdioFile SourceFile(FileName,CFile::modeRead);
CString strData;
while(??????)
{
SourceFile.ReadString(strData);
         }
请问while里面要表示读文件不到底(功能就像ifstream 中的.eof()一样),括号应该怎样写?

解决方案 »

  1.   

    while()中不用另加判断条件了,因为CStdioFile::ReadString()本身就是判断标志,若没有了(文件到头)返回NULL,因此:while(file.ReadString(s)){}就可.
      [程序实现]
      假设你已有了名为ts.txt的文件在你的工程目录下:
      {
       CStdioFile file;  
       CString sss;
       char ccc[100];
       DWORD o=0;
       int ol=0;
       file.Open("ts.txt",CFile::modeRead);
       while(file.ReadString(sss))
       {
          ol++;
          if(ol>1)//读两次就不读了.
             break;      
          
       }
       o=file.GetPosition();//记录上次的结果(读到哪了)
       .................
       file.Seek(o,0);//接着上回读
       while(file.ReadString(sss))
       {
          strcpy(ccc,sss);
          AfxMessageBox(ccc);
       }
      }