How do I use 3 and 4-byte Unicode characters with standard C++ strings?

前端 未结 5 1725
猫巷女王i
猫巷女王i 2020-12-24 09:01

In standard C++ we have char and wchar_t for storing characters. char can store values between 0x00 and 0xFF. And

5条回答
  •  抹茶落季
    2020-12-24 09:50

    char and wchar_t are not the only data types used for text strings. C++11 introduces new char16_t and char32_t data types and respective STL std::u16string and std::u32string typedefs of std::basic_string, to address the ambiquity of the wchar_t type, which has different sizes and encodings on different platforms. wchar_t is 16-bit on some platforms, suitable for UTF-16 encoding, but is 32-bit on other platforms, suitable for UTF-32 encoding instead. char16_t is specifically 16-bit and UTF-16, and char32_t is specifically 32-bit and UTF-32, on all platforms.

提交回复
热议问题