c++使用libiconv

来源:互联网 发布:手机腾讯视频网络错误1 编辑:程序博客网 时间:2024/04/29 09:33

做一个抓取的小项目使用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

0 0
原创粉丝点击