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);

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...