CString str;
CFile DstFile;
DstFile.Open(....);
GetDlgItemText(IDC_EDIT1,str);  //有中文
DstFile.Write(这里应该怎么写啊?);

解决方案 »

  1.   

    1.你打开时必须要有可写权限
    2.DstFile.Write(str,str.GetLength());
      

  2.   

    直接写……因为CString重载了一个operator const TCHAR*()的操作符,而CFile::Write第一个参数是const void*,所以只要直接传递就可以了(编译器会帮你转换)DstFile.Write(str, str.GetLength());
      

  3.   

    因为我的工程是UNICODE的,所以写出来的文件用16进制软件打开一看,变成这样子了:
    00000000h: 32 00 30 00 30 00 35 00 2D 00 37 00 2D 00 39 00 ; 2.0.0.5.-.7.-.9.
    00000010h: 20 00 31 00 32 00 30 00 30 00 35 00 2D 00 37 00 ;  .1.2.0.0.5.-.7.
    00000020h: 2D 00 39 00 20 00 31 00 32 00 30 00 30 00 35 00 ; -.9. .1.2.0.0.5.
    00000030h: 2D 00 37 00 2D 00 39 00 20 00 31 00             ; -.7.-.9. .1.请问这样怎么解决啊?
      

  4.   

    汗~~怎么CString的GetLength()方法把一个中文字的长度算成是1个长度啊,请问怎么取char类型的长度呢?
      

  5.   

    不是吧……GetLength就是取字节大小的……CString::GetLength 
    int GetLength( ) const;Return ValueA count of the bytes in the string.ResCall this member function to get a count of the bytes in this CString object. The count does not include a null terminator.For multibyte character sets (MBCS), GetLength counts each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two bytes.