#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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。