码迷,mamicode.com
首页 > 其他好文 > 详细

char* 转换为 CString 乱码问题(转)

时间:2014-12-02 14:59:42      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   color   os   sp   on   div   

bubuko.com,布布扣
 1 //计算char *数组大小,以字节为单位,一个汉字占两个字节
 2     int charLen = strlen(sText);
 3     //计算多字节字符的大小,按字符计算。
 4     int len = MultiByteToWideChar(CP_ACP,0,sText,charLen,NULL,0);
 5     //为宽字节字符数组申请空间,数组大小为按字节计算的多字节字符大小
 6     TCHAR *buf = new TCHAR[len + 1];
 7     //多字节编码转换成宽字节编码
 8     MultiByteToWideChar(CP_ACP,0,sText,charLen,buf,len);
 9     buf[len] = \0; //添加字符串结尾,注意不是len+1
10     //将TCHAR数组转换为CString
11     CString pWideChar;
12     pWideChar.Append(buf);
13     //删除缓冲区
14     delete []buf;
View Code

原文地址

去原文站点

char* 转换为 CString 乱码问题(转)

标签:style   blog   http   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/godboy1989/p/4137353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!