加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x在VS下中文显示

发布时间:2020-12-14 20:15:16 所属栏目:百科 来源:网络整理
导读:#include tchar.h #include string #include "iconviconv.h" #pragma comment(lib,"libiconv.lib") int GBKToUTF8(std::string gbkStr,const char* toCode,const char* fromCode) { iconv_t iconvH; iconvH = iconv_open(fromCode,toCode); if (iconvH == 0

#include <tchar.h>

#include <string>

#include "iconviconv.h"

#pragma comment(lib,"libiconv.lib")

int GBKToUTF8(std::string & gbkStr,const char* toCode,const char* fromCode)
{
iconv_t iconvH;
iconvH = iconv_open(fromCode,toCode);

if (iconvH == 0)
{
return -1;
}

const char* strChar = gbkStr.c_str();
const char** pin = &strChar;
size_t strLength = gbkStr.length();
char* outbuf = (char*) malloc(strLength*4);
char* pBuff = outbuf;


memset( outbuf,strLength*4);
size_t outLength = strLength*4;

if (-1 == iconv(iconvH,pin,&strLength,&outbuf,&outLength))
{
free(pBuff);
iconv_close(iconvH);
return -1;
}

gbkStr = pBuff;
free(pBuff);
iconv_close(iconvH);

return 0;
}


//使用方法

std::string str = "你好";

GBKToUTF8(str,"gbk","utf-8");

CCLabelTTF* label = CCLabelTTF::create(str.c_str(),"Arial",24);

this -> addChild(label);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读