cocos2d-x在VS下中文显示

cocos2d-x在VS下中文显示,第1张

概述#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; iconv

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

总结

以上是内存溢出为你收集整理的cocos2d-x在VS下中文显示全部内容,希望文章能够帮你解决cocos2d-x在VS下中文显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1037326.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存