为了账号安全,请及时绑定邮箱和手机立即绑定

怎么解决cocos2d-x3.0中文乱码

怎么解决cocos2d-x3.0中文乱码

桃花长相依 2019-01-02 16:01:16
怎么解决cocos2d-x3.0中文乱码
查看完整描述

1 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

可以写个字符编码转换的函数, 或者从外部读取UTF8格式的文件.转换函数可以用下面的, 记得include下iconv.h:

static char g_GBKConvUTF8Buf[1024] = {0};
const char* Utils::GBKToUTF8(const char *strChar)
{
iconv_t iconvH;
iconvH = iconv_open("utf-8","gb2312");
if (iconvH == 0)
{
return NULL;
}
size_t strLength = strlen(strChar);
size_t outLength = strLength << 2;
size_t copyLength = outLength;
memset(g_GBKConvUTF8Buf, 0, 5000);

char* outbuf = (char*) malloc(outLength);
char* pBuff = outbuf;
memset(outbuf, 0, outLength);

if (-1 == iconv(iconvH, &strChar, &strLength, &outbuf, &outLength))
{
iconv_close(iconvH);
return NULL;
}
memcpy(g_GBKConvUTF8Buf, pBuff, copyLength);
free(pBuff);
iconv_close(iconvH);
return g_GBKConvUTF8Buf;
}



查看完整回答
反对 回复 2019-01-05
  • 1 回答
  • 0 关注
  • 888 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信