免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6839 | 回复: 3
打印 上一主题 下一主题

[故障求助] AIX5.3下调用iconv_open失败,或提示Invalid argument,或提示Invalid wide character [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-13 17:47 |只看该作者 |倒序浏览
#include <iconv.h>
#include <iostream>
#include <stdio.h>

using namespace std;

bool UTF_8ToGB2312(char* pDst, char* pSrc)
{
    iconv_t conv;
    size_t uSrcLen;
    size_t uDstLen;

    //strerror(errno)的值,当字符集名称全为大写时是Invalid wide character,否则为Invalid argument
    conv = iconv_open("GBK","UTF-8");
    if(conv == (iconv_t)-1)
    {
        return false;
    }
   
    uSrcLen = strlen(pSrc);
    uDstLen = 200;
    memset(pDst, 0x00, uDstLen);

    if (-1 == iconv(conv, &pSrc, &uSrcLen, &pDst, &uDstLen))
    {
        iconv_close(conv);
        return false;
    }
  
    iconv_close(conv);
    return true;
}

int main()
{
    char *strUtf = "璋冪敤BOSS绯荤粺寮傚父锛岃?閲嶆柊灏濊瘯銆?";
    char strGb[200];
   
    if (UTF_8ToGB2312(strGb, strUtf))
    {
        cout<<strGb<<endl;
    }
    else
    {
        cout<<"failed"<<endl;
    }
    return 0;
}



用iconv -l查看,GBK和UTF-8都是有的。

另外,用命令行iconv -f UTF-8 -t GB2312 my.txt,是可以转换成功的。

谁遇过类似的问题,大家帮帮忙!

[ 本帖最后由 lingat242 于 2009-7-20 10:10 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-08-03 14:42 |只看该作者
没有人知道吗?

论坛徽章:
0
3 [报告]
发表于 2010-05-28 23:13 |只看该作者
回复 1# lingat242
与链接的动态库有关

    如果你要用g++ -o -m32 test.cpp编译就会调用lib/libiconv库
如果要用g++ -o test.cpp编译就会调用lib64/libiconv

上述两种情况试试看那种支持

论坛徽章:
0
4 [报告]
发表于 2012-08-07 15:50 |只看该作者
GBK 问题吧 ic=iconv_open("GB2312","UTF-8");  我的通过了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP