我们先来看一下CStdioFile这个类:
class CStdioFile : public CFile。
它是从CFile类继承过来的。除了构造函数它只提供了两个函数:
virtual LPTSTR ReadString(LPTSTR lpsz,UINT nMax );读文本的一行。
virtual BOOL ReadString(CString& rString);写文本的一行。
CStdioFile hFile;
CFileException ex;
BOOL isEof=FALSE;
if (!hFile.Open(m_hFilePath,CFile::modeRead | CFile::shareDenyWrite, &ex)) //打开文件
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
return;
}else
{
while(!isEof)
{
isEof=!hFile.ReadString(strTemp);//读取一行文本。
if(isEof) break;
……..do something
}
}
CString strTmp;
strTmp=“写一行文本/n”;
hFile.WriteString(strTmp);