[英]Output UTF-8 (u8) std::string
In C++11 and later, using the u8
prefix on a string literal can create char
(byte) sequences that are UTF-8 encoded. 在C ++ 11和更高版本中,在字符串文字上使用
u8
前缀可以创建经过UTF-8编码的char
(字节)序列。
How do you output those sequences to a std::ostream
? 如何将这些序列输出到
std::ostream
? How do you tell a std::ostream
that a const char *
or std:string
to be output contains characters encoded in UTF-8, rather than the default encoding? 您如何告诉
std::ostream
要输出的const char *
或std:string
包含以UTF-8编码的字符,而不是默认编码?
You don't. 你不知道 The stream does not know or care what the encoding of the text is.
流不知道或不在乎文本的编码是什么。 Despite it's name, a
char
is not treated by std:ostream
as containing a character encoded in the platform encoding. 尽管有其名称,但
std:ostream
并未将char
视为包含以平台编码方式编码的字符。 It must treats a char
as a byte to be written out. 它必须将
char
视为要写入的字节。 It writes the "text" (byte sequence) as given (outside of possibly performing \\n
translation), assuming you don't imbue it with a facet that changes this. 假设您不给它加上刻面来改变它,它会按照给定的方式(文本可能会执行
\\n
转换)写入“文本”(字节序列)。 If you write characters that conform to UTF-8, then that's what ends up in the output. 如果您编写符合UTF-8的字符,那么最终结果就是输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.