Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我可以在ICU中从char*转换为UChar吗?_C++_Icu - Fatal编程技术网

C++ 我可以在ICU中从char*转换为UChar吗?

C++ 我可以在ICU中从char*转换为UChar吗?,c++,icu,C++,Icu,我有一个char*(包含utf-8字符串),我想将其传递给ICU以将其转换为ANSI(ISO-8859-6)。不幸的是,大多数ICU功能似乎采用UChar而不是char* 如何进行转换?您看过文档了吗?脱颖而出 // given char* str UnicodeString ustr = UnicodeString::fromUTF8(StringPiece(str)); 我假设您知道如何使用将ustr转换为所需的代码页。您可以使用来自UTF8的静态成员函数将UTF-8StringPiece

我有一个char*(包含utf-8字符串),我想将其传递给ICU以将其转换为ANSI(ISO-8859-6)。不幸的是,大多数ICU功能似乎采用UChar而不是char*

如何进行转换?

您看过文档了吗?脱颖而出

// given char* str
UnicodeString ustr = UnicodeString::fromUTF8(StringPiece(str));

我假设您知道如何使用将
ustr
转换为所需的代码页。

您可以使用来自UTF8的静态成员函数
将UTF-8
StringPiece
转换为
UnicodeString
。因此,如果你有一个char*,你可以这样转换它:

const char* str;
size_t len;
UnicodeString ucs = UnicodeString::FromUTF8(StringPiece(str, len));

“包含Unicode字符”=UTF-8?
char*
作为一种类型,没有给出底层编码的指示;编码是最重要的部分。@KennyTM是utf-8(谢谢我编辑了这个问题)