现在有一文本文件dev.txt,假设有三行内容
line1  //第一行
line2  //第二行
line3  //第三行
实现代码:
CStdioFile file;
CString m_strTemp;
file.Open("dev.txt",CStdioFile::modeRead);
file.ReadString(m_strTemp);//读取第一行line1,并将内容存放在m_strTemp中
现在怎么让程序接着继续往下,分别读取第二行line2和第三行line3?

解决方案 »

  1.   

    while(file.ReadString(m_strTemp))
    {
    }
      

  2.   

    CStdioFile::ReadString  Reads text data into a buffer, up to a limit of nMax–1 characters, from the file associated with the CStdioFile object.virtual LPTSTR ReadString(
       LPTSTR lpsz,
       UINT nMax 
    );
    virtual BOOL ReadString(
       CString& rString
    );
    Parameters
    lpsz
    Specifies a pointer to a user-supplied buffer that will receive a null-terminated text string.nMax
    Specifies the maximum number of characters to read, not counting the terminating null character.rString
    A reference to a CString object that will contain the string when the function returns.Return ValueA pointer to the buffer containing the text data. NULL if end-of-file was reached without reading any data; or if boolean, FALSE if end-of-file was reached without reading any data.   // 注意最后一个句子
      

  3.   

    while(file.ReadString(m_strTemp))
    {
    }
      

  4.   

    while里面即可,函数有返回值的,到结尾就返回false