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