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