有一个Unicode编码的配置文件,几乎纯英文的,现在需要写程序在其中查找替换一个变量
类似这样的:
"SourceIP"="192.168.0.1"
想要将IP地址按照用户在GUI中填写的数值替换掉,
请问在MFC中怎么实现?
用CFile的话好像没办法往文件写入Unicode编码的字符串
如果用wchar_t做buffer读出的文件内容中有少数字符显示为??
不知道要怎么办
清高手赐教~!!

解决方案 »

  1.   

    可以通过_UNICODE,UNICODE的宏定义,在mfc中完全适用unicode编码,应该能解决这个问题
      

  2.   

    Before using CString to replace characters, please make sure that encoding is only UTF-16(unicode) format without UTF-8. CString doesn't seems to correctly work with UTF-8.
    Actually, you want to write Unicode text, you should specify how many buffer size in bytes when performing CFile::Write.
    Note:If the file starts with a Unicode byte-order  [0xFF 0xFE] or [0xFE 0xFF], the document is considered to be in UTF-16 encoding. Otherwise it is in UTF-8.
      

  3.   


    WideCharToMultiByte用他吧,很强的.
      

  4.   

    to jiangsheng:
      CStringW类可以直接用么 也就是说我可以把文件通过CFile.Read,以wchar_t做的buffer读到CStringW,然后再用CStringW::Replace来替换字段么?最后我要怎么把处理过的CStringW写回原文件?to yjgx007:
      我的文件头部没有标识字节,如果用notepad打开再保存的话会加上FF FE标识,但是原文件一开始就是数据段了。而且我用wchar_t做buffer读出的内容中少部分无法正常显示,而是显示为"??"
      

  5.   

    ff fe是unicode的标识,你还是定义_UNICODE宏比较好