Is the u8 string literal necessary in C++11

前端 未结 4 1689
鱼传尺愫
鱼传尺愫 2020-12-13 19:11

From Wikipedia:

For the purpose of enhancing support for Unicode in C++ compilers, the definition of the type char has been modified to be at least th

4条回答
  •  遥遥无期
    2020-12-13 19:47

    If the execution character set of the compiler is set to UTF-8, it makes no difference if u8 is used or not, since the compiler converts the characters to UTF-8 in both cases.

    However if the compilers execution character set is the system's non UTF8 codepage (default for e.g. Visual C++), then non ASCII characters might not properly handled when u8 is omitted. For example, the conversion to wide strings will crash e.g. in VS15:

    std::string narrowJapanese("スタークラフト");
    std::wstring_convert, wchar_t> convertWindows;
    std::wstring wide = convertWindows.from_bytes(narrowJapanese); // Unhandled C++ exception in xlocbuf.
    

提交回复
热议问题