MFC把CString字符串保存在xml文件中格式不对了(如下图)?

之前的格式
图片说明
保存后的格式
图片说明

写.xml文件代码如下:
CFile file;
CString FileName=_T("idx_file1.xml");
file.Open(FileName,CFile::modeCreate|CFile::modeWrite);
file.SeekToBegin();
file.Write((unsigned char *)(strText.GetBuffer(0)),strText.GetLength());//CString strText
file.Flush();
file.Close();

可能是编码问题, 用16进制编辑器打开看看

用utf8编码CString,然后再写入文件。

你最后保存的是unicode编码的格式吧~

你的工程应该是使用Unicode编码,那么你可以先将CString数据转成char【】,然后再将char[]的数据写入文件中。