vc中常用文件操作(四)CStdioFile

CFile的派生类CStdioFile提供了对文件进行流式的操作功能。其中函数void CStdioFile::WriteString( LPCTSTR lpsz )写入一个字符串,需要给字符串lpsz的末尾加上换行标志”\r\n”;函数bool CStdioFile::ReadString(CString &rString )从文件中读取一行,如果文件未读完返回true,否则返回false。

比如:写入文件的例子

//创建文件


CStdioFile file;

//写入文件

CString str;

//关闭文件

file.Close();

比如:读文件的例子

CString strText = “”;

//打开文件

//逐行读取字符串

MessageBox(strText);

//关闭文件

file.Close();

原文地址:https://www.cnblogs.com/syxchina/p/2197299.html