CStdioFile mFile; CFileException mExcept; mFile.Open(_T("D:\\TEST.ini"),CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite,&mExcept); mFile.SeekToEnd(); CString stroutput = "I am a string"; stroutput += "\r\n"; mFile.WriteString(stroutput); CString stroutput2 = "I am a string2"; stroutput2 += "\r\n"; mFile.WriteString(stroutput2); mFile.Close();
1.只有CFile::modeCreate | CFile::modeWrite
文件存在时清空,不存在时新建
2.CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite
文件不存在时新建,文件存在时不清空,直接从头开始覆盖
3.CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite 与mFile.SeekToEnd()搭配使用
文件不存在时新建,文件存在时,不清空,从文件末尾开始添加(追加)