0

我在 AIX 上使用 c++/XMS 来使用来自 MQ 的传入消息。现在我需要将消息从 ISO8859-1 转换为 UTF-8。我执行以下操作。

==================================================== ====

void iso2utf8( char* text_iso, char* text_utf8, int nLen)
{
    cout << "Converting to UTF-8." << endl;
    iconv_t ic;
    ic = iconv_open("UTF-8", "ISO8859-1"); // iso->utf8
    cout << "Size of text_iso" << sizeof(text_iso) << endl;

    size_t il = nLen;
    size_t ol = nLen;

    cout << "Size of text_iso" << ol << endl;
    iconv(ic , &text_iso, &il, &text_utf8, &ol);
    iconv_close(ic);

    cout << "Message in UTF-8: " << text_utf8 << endl;

    return;
}

==================================================== ====

转换后,当我将消息保存到文件中时,我会返回 ISO8859-1 消息。有关如何解决此问题的任何提示。我使用 fstream 写入文件。

4

1 回答 1

0

你应该写“ISO-8859-1”而不是“ISO8859-1”

链接到 iconv 人: https ://www.gnu.org/software/libiconv/documentation/libiconv-1.13/iconv_open.3.html

引用: fromcode 和 tocode 允许的值以及支持的组合取决于系统。对于 libiconv 库,所有组合都支持以下编码。

欧洲语言

ASCII, ISO−8859−{1,2,3,4,5,7,9,10,13,14,15,16} ...

于 2021-08-05T09:58:51.113 回答