[MFC] 从文件读取与向文件添加数据

CString str,str2,str3;str2="dsf",str3="dsfds";
CStdioFile myFile, File;
if(myFile.Open(_T("D:\\filename.txt"), CFile::modeRead))
{
    //读取
    myFile.ReadString(str); 
    myFile.Close();
}
else
{
    //创建
    File.Open(_T("D:\\filename.txt"), CFile::modeWrite | CFile::modeCreate);  
    File.WriteString(str2);
    File.Close();
} 
//写入
File.Open(_T("D:\\filename.txt"), CFile::modeWrite );      
File.WriteString(str3);   
File.Close();

 

posted @ 2013-12-10 16:38  beautifulzzzz  阅读(1506)  评论(0编辑  收藏  举报