加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

linux下使用iconv转换编码:UTF8转GBK

(2012-03-08 18:25:43)
标签:

字符编码

iconv

it

分类: MyOS
  1. #include <sys/types.h>
  2. #include <iconv.h>
  3. #include <stdio.h>
  4. using namespace std;
  5. char UTF8toANSI(const std::string &from){
  6.     char *inbuf=const_cast<char*>(from.c_str());
  7.     size_t inlen strlen(inbuf);
  8.     size_t outlen inlen *4;
  9.     char *outbuf (char *)malloc(inlen );
  10.     bzero( outbuf, inlen 4);
  11.     char *in inbuf;
  12.     char *out outbuf;
  13.     iconv_t cd=iconv_open("GBK","UTF-8");
  14.     iconv(cd,&in,&inlen,&out,&outlen);
  15.     iconv_close(cd);
  16.     return outbuf;
  17. }

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有