Is the u8 string literal necessary in C++11

前端 未结 4 1687
鱼传尺愫
鱼传尺愫 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:54

    The encoding of "Test String" is the implementation-defined system encoding (the narrow, possibly multibyte one).

    The encoding of u8"Test String" is always UTF-8.

    The examples aren't terribly telling. If you included some Unicode literals (such as \U0010FFFF) into the string, then you would always get those (encoded as UTF-8), but whether they could be expressed in the system-encoded string, and if yes what their value would be, is implementation-defined.

    If it helps, imagine you're authoring the source code on an EBCDIC machine. Then the literal "Test String" is always EBCDIC-encoded in the source file itself, but the u8-initialized array contains UTF-8 encoded values, whereas the first array contains EBCDIC-encoded values.

提交回复
热议问题