项目中的一个文件原来不知道是什么编码写的。。 用记事本打开时正常的。
比如下面的
 <Attachments>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg"/>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_2.jpg"/>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_3.jpg"/>
    <Attachment RelPath="images\thumb_01.jpg"/>
</Attachments>
我在程序中用open函数在_O_READ 模式下打开,结果但不调试的时候显示
:\Documents and Settings\Administrator\妗岄潰\绱犳潗\0913R1.files\images\0913R1_c_1.jpg
中文就是乱码了。  然后我复制上面的内容新建一个记事本保存后,有同样的方式打开就是正确的,不出现乱码,这个是为什么,我怎么才能直接获得正确 RelPath而非乱码,卡在这里两天了,各位帮忙。。

解决方案 »

  1.   

    if (-1 == (fd = open(strFileNameXML,  _O_RDONLY))) 
    return -1;
        char szBuffer[10*1024]={0};
        int nReadBytes=0;
        if( ( nReadBytes = read( fd, szBuffer, sizeof(szBuffer) ) )<= 0 )  //数据全部在szBuffer中
    这样子行不行?
      

  2.   

    notepad支持多种编码,而你这种方式是不知道编码的,你在假定文档是用当前locale编码的,当然是有问题的我估计你的代码是unicode写的,检查文档的第1、2两个字节,应该是0xFF 0xFE
    如果是:你必须用binary模式打开,读进来一行用W2A转换
      

  3.   

    使用IsTextUnicode检查文件编码.
      

  4.   

    既然notepad可以打开,你可以用它打开,然后选择文件、另存为,选择encoding格式为ansi,这样的文件就可以被你代码打开了
      

  5.   

    我估计也是啊,我读取的是XML文档,XML应该就是Unicode编码的。。