c++ - 在 C++ 中使用 utf8 库将 UTF 16 转换为 UTF8

标签 c++ utf-8 utf-16

我正在使用 this库在 C++ 中进行从 UTF16 到 UTF8 的转换。

该示例建议使用以下方法将 utf16 转换为 utf8:

unsigned short utf16string[] = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};
vector<unsigned char> utf8result;
utf16to8(utf16string, utf16string + 5, back_inserter(utf8result));
assert (utf8result.size() == 10);    

其中 utf16to8 的定义由:

template <typename u16bit_iterator, typename octet_iterator>
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result);

我有一个 char 数组,其中包含 UTF16 中的字符。如果我不知道我的 UTF16 字符数组的大小(有效字符数),你能告诉我是否仍然可以使用这个库吗?

最佳答案

没有。显然,您无法对存储在大小未知的容器中的数据做任何有意义的事情。您应该知道它包含多少个元素。

关于c++ - 在 C++ 中使用 utf8 库将 UTF 16 转换为 UTF8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21677979/

相关文章:

c++ - 数据何时在 SSE 寄存器和堆栈之间移动?

c# - 在 .Net 中使用大于 2 个字节的 unicode 字符

php - UTF-8贯穿始终

读取带有BOM的UTF-8文本文件

c++ - 如果我将 basic_stream<char> 与 codecvt_utf16<char> facet 的语言环境相结合,会发生什么情况?

c# - 我的应用程序的内部编码

使用 while 循环的 C++ 可能的硬币组合

c++ - 对 boost::locale:conv::between 的 undefined reference

c++ - 快速 C++ 字符串输出

ruby - 将转义的 unicode 字符串转换为 ruby​​ 1.8 中的字符