码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx 3.0 中文 iconv 转换函数

时间:2014-06-05 19:25:43      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

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 转换函数

标签:c   style   class   blog   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!