CStdioFile.WriteString向文件中写入字符串,但字符串中带有中文的,无法写入。
解决方案:
- 将带有中文的字符串进行转换后再写入文件。
- char* pBuffer = NULL;
- long lBufferSize;
- lBufferSize = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, m_sRtf, -1, NULL, 0, NULL, NULL);
- pBuffer = new char[lBufferSize + 1];
- WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, m_sRtf, -1, pBuffer, lBufferSize + 1, NULL, NULL);
- CFile file(_T("E://a.rtf"), CFile::modeCreate | CFile::modeWrite);
- file.Write(pBuffer, lBufferSize);
- file.Close();
- 保存文件前调用setlocale函数。
- setlocale(LC_CTYPE, ("chs"));