您的位置:首页 > 其它

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

2016-04-05 21:51 211 查看

写入文件的例子

//创建文件

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  txt log 日志 记录 文本