中文字符

http://blog.csdn.net/zhy_cheng/article/details/8268814 参考此神牛

Windows默认的字符集是GB2312,而Cocos2d-x使用的是UTF-8,所以要将我们的字符先转为UTF-8,转换方法是使用下面的函数:

char* HelloWorld::G2U(const char* gb2312)  
{  
 int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);  
 wchar_t* wstr = new wchar_t[len+1];  
 memset(wstr, 0, len+1);  
 MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);  
 len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);  
 char* str = new char[len+1];  
 memset(str, 0, len+1);  
 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);  
 if(wstr) delete[] wstr;  
 return str;  
}

 

posted @ 2014-01-07 23:07  phk52  阅读(187)  评论(0)    收藏  举报