cocos2d-x在VS下中文显示

前端之家收集整理的这篇文章主要介绍了cocos2d-x在VS下中文显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

#include <tchar.h>

#include <string>

#include "iconv\iconv.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);

原文链接:https://www.f2er.com/cocos2dx/344590.html

猜你在找的Cocos2d-x相关文章