close
#include <iostream>
#include <fstream>
#include <iconv.h>
int
main(
int
argc,
char
*argv[])
{
char
src[] =
"abcčde"
;
char
dst[100];
size_t
srclen = 6;
size_t
dstlen = 12;
fprintf
(stderr,
"in: %s\n"
,src);
char
* pIn = src;
char
* pOut = (
char
*)dst;
iconv_t conv = iconv_open(
"UTF-8"
,
"CP1250"
);
iconv(conv, &pIn, &srclen, &pOut, &dstlen);
iconv_close(conv);
fprintf
(stderr,
"out: %s\n"
,dst);
}
這裡要注意 iconv(conv, &pIn, &srclen, &pOut, &dstlen);
若返回 -1 則要查看
錯誤處理 errno
若是 #define E2BIG 7 /* Arg list too long */
則表示 dstlen 給的長度小於 轉換後的長度!!
範例
https://blog.inventic.eu/2010/11/simple-iconv-libiconv-example/
錯誤處理 errno
http://blog.liang.tw/?p=264
全站熱搜
留言列表