[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();

 

你可能感兴趣的:(文件读取)