Learn How to Use C++ Unicode String Literals For Windows Development With C++Builder
C++ supports various string and character types, and provides ways to express literal values of each of these types.
A string literal represents a sequence of characters that together form a null-terminated string. The characters must be enclosed between double quotation marks. There are the following kinds of string literals:
- Narrow string literals
- UTF-8 encoded strings
- Wide string literals
- char16_t and char32_t (C++ 11)
- Raw string literals (C++ 11)
- std::string literals (C++14)
C++11 introduces new character types to manipulate Unicode string literals. Such portable types are char16_t
(16-bit Unicode) and char32_t
(32-bit Unicode) character types. It added the literal prefixes u8, u and U that specify known sizes and encodings, respectively UTF-8, UTF-16 and UTF-32. But no matter whether one chooses u8, u or U, the code needs added runtime conversions on one or the other platform.
auto s3 = u"hello"; // const char16_t* auto s4 = U"hello"; // const char32_t*
On top of this one can directly use Unicode escape sequences to code a certain symbol without having to worry about encoding.
const char16_t* s16 = u"u00DA"; const char32_t* s32 = U"u00DA";
Head over and find out more about all of the latest modern C++ features in the Embarcadero DocWiki.
Leave Your Comment