CStdioFile类逐行读写日志记录文件

原文地址为: CStdioFile类逐行读写日志记录文件


写入文件的例子
//创建文件
CStdioFile file;
file.Open("ts.txt",CFile::modeCreate|CFile::modeWrite);
//写入文件
CString str;
str.Format("%s\r\n","hello!I am talkingmute!");(在末尾添加\r\n会导致写出来的文档修改后出现格式错乱,只能写\n)
file.Seek(0,CFile::end);
file.WriteString( str );
//关闭文件
file.Close();
比如:读文件的例子
CString strText = “”;
CString szLine = “”;
//打开文件
CStdioFile file;
file.Open("ts.txt",CFile::modeRead);
//逐行读取字符串
while( file.ReadString( szLine ) )
{
strText += szLine;
}
MessageBox(strText);
//关闭文件
file.Close();

转载请注明本文地址: CStdioFile类逐行读写日志记录文件

猜你喜欢

转载自blog.csdn.net/wangchaoqi1985/article/details/80970865
今日推荐