C++ ICU提取函数生成不可打印的字符

C++ ICU提取函数生成不可打印的字符,c++,unicode,icu,C++,Unicode,Icu,我收到一个来自供应商的Unicode字符串。我相信他们正在使用UTF-16。我需要将其转换为UTF-8,以便在代码中进行操作。我用它来处理Unicode。尝试toUTF8String方法时,我得到的字符显示为颠倒的问号。在尝试提取方法时,我也得到了相同的输出 #include "unicode/utypes.h" #include "unicode/ucnv.h" #include "unicode/ustring.h" #include "unicode/uchar.h" #include "

我收到一个来自供应商的Unicode字符串。我相信他们正在使用UTF-16。我需要将其转换为UTF-8,以便在代码中进行操作。我用它来处理Unicode。尝试toUTF8String方法时,我得到的字符显示为颠倒的问号。在尝试提取方法时,我也得到了相同的输出

#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "unicode/ustring.h"
#include "unicode/uchar.h"
#include "unicode/uloc.h"
#include "unicode/unistr.h"

// RawMessage is received as void *
void ReceiveMessage(  RawMessage )
{
    UChar * UCharUnicodeMessage;
    UCharUnicodeMessage = (UChar*)RawMessage;
    UnicodeString in(UcharUnicodeMessage);
    UErrorCode status = U_ZERO_ERROR;
    char dest[in.length()];
    int ln = in.extract(dest,in.length(), NULL, status);
    cout << endl << "***** Unicode String Received from AEM: " << dest << endl;
    string response;
    in.toUTF8String(response);
    cout << "Result of toUTF8String: " << response;
    // Writes this to our database, the 5 and 19 are debug codes
    LogLongMessage("Test", 5, 19, (char*)response.c_str());
}
我的数据库显示以下内容: ??????{FaultResponse sequenceNumber=10000001} {Exception type=System.ArgumentException} {message}没有插入或更新的记录{/message} {detail}System.ArgumentException:没有插入或更新的记录{/detail} {/Exception}
{/FaultResponse}攀

如果我使用cout,我会得到以下输出:䵚㌵簶 没有插入或更新系统的记录。ArgumentException:没有先插入或更新的记录,它是Unicode,而不是Unicode。然后,您说您从供应商处收到一个Unicode字符串,但该字符串的编码是什么,例如UTF-8?如果不知道这一点,则无法正确解码接收到的字节。也就是说,您的代码示例还不够。首先,它应该是完整的,包括不能解码的字节。第二,请在这里在线发布。有关更多信息,请参阅的张贴指南。