cocos2dx 3.0 中文 iconv 转换函数
//#include <string> #pragma once #include "cocos2d.h"; #include "iconv\include\iconv.h" //#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) // 编译链接的时候指定静态库 //#pragma comment(lib,"libiconv.lib") //#endif int convert(char *from_charset, char *to_charset, const char *inbuf, size_t inlen, char *outbuf, size_t outlen) { iconv_t cd; const char* temp = inbuf; const char** pin = &temp; char** pout = &outbuf; memset(outbuf,0,outlen); cd = iconv_open(to_charset,from_charset); if(cd==0) return -1; if(iconv(cd,(char**)pin,&inlen,pout,&outlen) == -1) return -1; return 0; } std::string tochinese(const char *inbuf){ size_t inleng = strlen(inbuf); char* outbuf = new char[inleng * 2 +2]; std::string strRet; if(convert("gb2312","utf-8",inbuf,inleng,outbuf,inleng*2+2)==0) strRet = outbuf; delete[] outbuf; return strRet; }