首页 > 其他 > 详细

cocos2dx 3.0 中文 iconv 转换函数

时间:2014-06-05 19:25:59      阅读:448      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
//#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;
}
bubuko.com,布布扣

 

cocos2dx 3.0 中文 iconv 转换函数,布布扣,bubuko.com

cocos2dx 3.0 中文 iconv 转换函数

原文:http://www.cnblogs.com/GameCode/p/3768255.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!