c++ - 使用 unicode 字符串作为 std::vector<unsigned short>

标签 c++

库将 unicode 字符串存储为。

std::vector<unsigned short> ustring;

我如何以可移植的方式进行这些转换?

convert ustring to std::wstring;
convert ustring to std::string;
convert ustring to std::vector<unsigned char>;
convert std::vector<unsigned char> to ustring;


编辑
字符串可能是 UTF-16 而不是 UTF-8

最佳答案

libiconv , icu , UTF8-CPP ,其他人可以做到这一点。 AFAIK,C++ 没有在 UTF8/16/32 之间转换的可移植方式。请记住,std::wstring 在某些系统上是 UTF16,而在其他系统上是 UTF32。

关于c++ - 使用 unicode 字符串作为 std::vector<unsigned short>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7968877/

相关文章:

c++ - 为什么在 Windows C++ 项目中使用 asm 文件?

c++ - 未收到 Windows 多点触控 TOUCHEVENTF_UP

c++ - 如何对 .exe 附带的外部文件进行编码

c++ - Qt_USE_MATH_DEFINES

c++ - 在 C++ 中使用枚举进行 for 循环

多次打印 C++ 消息

c++ - 确定最佳转换的 Variadic 模板

c++ - 如何检查两个任意内存范围在 c/c++ 中不重叠

c++ - 在 std::function 和 lambda 中使用自动说明符

c++ - 使用 C 字符串会给出警告 : "Address of stack memory associated with local variable returned"