写入文件mfc

时间:2012-06-01 09:51:20

标签: c++ file unicode mfc

如何使用MFC将unicode写入文件。我尝试使用Cfile类写入文件但不确定如何指定TCHAR的长度也无法打印出新行。欢迎使用代码段。

1 个答案:

答案 0 :(得分:3)

如果要将\ n自动转换为\ r \ n字符,请使用CStdioFile和方法ReadString / WriteString。以下示例使用CFile:

CString strFileContent;
CString strFilePath; 

CFile theFile(strFilePath, CFile::modeReadWrite | CFile::modeCreate);

// write BOM if you like
// WCHAR bom = 0xFEFF;
// theFile.Write(&bom, 2);

theFile.Write( (LPCTSTR) strFileContent, 
    strFileContent.GetLength() * sizeof(TCHAR));
相关问题