c++使用libiconv

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

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

#include <iostream>
#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值