关于利用 iconv 跨平台转编码问题
string name = "Ambition";
GBKToUTF8(name,"GBK","UTF-8"); //需要转换什么编码只需要更改后面2个参数。万能的(嘎嘎。。。。)
游戏开发群:44727718
int JCStrCoding::GBKToUTF8(string &gbkStr,const char* toCode/*="gbk"*/,const char* fromCode/*="utf-8"*/)
{
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 strLenth = gbkStr.length();
char *outbuf = (char *)malloc(strLenth *4);
char* pBuff = outbuf;
memset(outbuf,0,strLenth*4);
size_t outLength = strLenth*4;
if( -1 == iconv(iconvH,pin,&strLenth,&outbuf,&outLength))
{
iconv_close(iconvH);
return -1;
}
gbkStr = pBuff;
iconv_close(iconvH);
return 0;
}
这个 iconv 库到网上去下个就行了。。只需使用他的lib 跟头文件就可以 。。。。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步