设为首页 加入收藏

TOP

c++使用libiconv
2016-12-06 20:24:34 】 浏览:248
Tags:使用 libiconv

做一个抓取的小项目使用c++调用libiconv
一直提示报错 No matching function call iconv

在c下能调用,在c++下无法调用。
是命名冲突的问题,新建一个namespace即可

#include 
  
   
#include "stdio.h"
#include "string.h"

namespace myconv{
    #include "iconv.h"
}

using namespace std;

int main()
{
    string res = "编码转换,从gbk到utf-8";
    char *inChar = (char*)res.c_str();
    myconv::iconv_t convObj = myconv::iconv_open("GBK","UTF-8");
    size_t inLen,outLen;
    inLen = strlen(inChar);
    outLen = inLen+1;
    char outTxt[outLen];
    char *outChar = outTxt;
    myconv::iconv(convObj, &inChar, &inLen, &outChar, &outLen);
    myconv::iconv_close(convObj);
    string newRes(outTxt);
    cout << newRes;
    return 0;
}
  

基于c的编码转换,参考链接
官网http://www.gnu.org/software/libiconv/
使用http://www.cnblogs.com/1024incn/p/3924528.html

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇堆结构:最大堆 下一篇RNN递归神经网络 C++实现

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目