#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)
{
@H_403_12@iconv_t iconvH;
@H_403_12@iconvH = iconv_open(fromCode,toCode);
@H_403_12@
@H_403_12@if (iconvH == 0)
@H_403_12@{
@H_403_12@return -1;
@H_403_12@}
@H_403_12@
@H_403_12@const char* strChar = gbkStr.c_str();
@H_403_12@const char** pin = &strChar;
@H_403_12@size_t strLength = gbkStr.length();
@H_403_12@char* outbuf = (char*) malloc(strLength*4);
@H_403_12@char* pBuff = outbuf;
@H_403_12@memset( outbuf,strLength*4);
@H_403_12@size_t outLength = strLength*4;
@H_403_12@
@H_403_12@if (-1 == iconv(iconvH,pin,&strLength,&outbuf,&outLength))
@H_403_12@{
@H_403_12@free(pBuff);
@H_403_12@iconv_close(iconvH);
@H_403_12@return -1;
@H_403_12@}
@H_403_12@
@H_403_12@gbkStr = pBuff;
@H_403_12@free(pBuff);
@H_403_12@iconv_close(iconvH);
@H_403_12@
@H_403_12@return 0;
}
//使用方法
std::string str = "你好";
GBKToUTF8(str,"gbk","utf-8");
CCLabelTTF* label = CCLabelTTF::create(str.c_str(),"Arial",24);
this -> addChild(label);