Windows下的字符编码默认是gb2312 在Linux下需要转成utf8 才能正确的看到对应的中文编码 提供转换函数

/*---------------------------------------------------
Date: 2014-12-15
Author: fangjunmin
Modify:
Description: 编码转换模块
----------------------------------------------------*/
#include "encode.h"
#include "stdio.h"
#include <errno.h>
#include <iconv.h> bool ConvertEncode( const char *from_charset, const char *to_charset, char *inbuf , size_t inlen,char *outbuf, size_t& outlen )
{
char *pin = inbuf;
char *pout = outbuf;
size_t ulInLen = inlen;
size_t ulOutLen = outlen; iconv_t cd = iconv_open(to_charset, from_charset);
if( cd == (iconv_t)(-1) )
{
return false;
} memset(outbuf, 0, outlen);
int nRet = iconv(cd, &pin, (size_t*)&ulInLen, &pout, (size_t*)&ulOutLen);
iconv_close(cd); //切记 outlen -= ulOutLen; if( nRet == -1 )
{
int nError = errno;
switch( nError)
{
case EINVAL:
{
return true;
}
case E2BIG:
{
printf("转码失败,转码缓冲不够\n系统错误信息:%m\n");
return false;
}
case EILSEQ:
{
printf("转码失败(有可能同码相转)\n系统错误信息:%m\n");
return false;
}
default:
{
printf("转码失败\n系统错误信息:%m\n");
return false;
}
}
} return true;
} bool GB2312ToUtf8(const char* szSrc, int iSrcLen, char* szDst, size_t& iDstLen)
{
return ConvertEncode("GB18030", "utf-8", (char*)szSrc, iSrcLen, szDst, iDstLen);
}

  

最新文章

  1. Kubernets搭建Kubernetes-dashboard
  2. 总结Oracle删除表空间遇到的问题
  3. WORDPRESS点击标题或图片无法链接到文章页面
  4. .net之工作流工程展示及代码分享(一)工作流表单
  5. PHP实现发红包程序
  6. C++析构函数调用异常问题研究
  7. asp.net中导出Excel的方法
  8. socket本地模拟TCP 服务器+客户端(二)
  9. 行为驱动开发(BDD)
  10. xamarin android checkbox自定义样式
  11. Python 中的继承、多态和封装
  12. 索引法则--IS NULL, IS NOT NULL 也无法使用索引
  13. 并发库应用之十二 &amp; 常用集合问题汇总
  14. Python合并多个Excel数据
  15. 工作中bug笔记
  16. 2.5 Apache Axis2 快速学习手册之JiBx 构建Web Service
  17. 使用Python + Selenium破解滑块验证码
  18. python中函数嵌套、函数作为变量以及闭包的原理
  19. IOS 7层协议
  20. CGLIB代理基础

热门文章

  1. 执行dlsym()函数出现: undefined symbol
  2. IDA Pro - 使用IDA Pro逆向C++程序
  3. java 学习笔记(四) java连接ZooKeeper
  4. linux ngxtop安装安装及使用
  5. Gym - 102082G What Goes Up Must Come Down (树状数组+贪心)
  6. uniapp开发微信小程序跳转出现navigateTo:fail page &quot;pages/user/pages/user/address/address&quot; is not found
  7. 【leetcode】Department Top Three Salaries
  8. Python基础-day05
  9. HTML的状态码
  10. TTTTTTTTTTTTT CF Good Bye 2015 C- New Year and Domino(CF611C) 二维前缀