std::codecvt_mode
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <locale> 中定义
|
||
enum codecvt_mode { consume_header = 4, |
||
方面std::codecvt_utf8,std::codecvt_utf16,std::codecvt_utf8_utf16接受一个可选的值类型std::codecvt_mode作为一个模板参数,它指定的unicode字符串转换的可选功能.
原文:
The facets std::codecvt_utf8, std::codecvt_utf16, and std::codecvt_utf8_utf16 accept an optional value of type std::codecvt_mode as a template argument, which specifies optional features of the unicode string conversion.
[编辑] 常量
在头文件
<locale> 中定义 | |
值
|
Meaning |
little_endian
|
假设输入的是little-endian字节顺序(只适用于UTF-16的输入,默认的是big-endian)
原文: assume the input is in little-endian byte order (applies to UTF-16 input only, the default is big-endian) |
consume_header
|
消耗的字节顺序标记,如果存在的话在开始的输入序列(UTF-16的情况下),依靠它指定的字节顺序解码其余的输入
原文: consume the byte order mark, if present at the start of input sequence, and (in case of UTF-16), rely on the byte order it specifies for decoding the rest of the input |
generate_header
|
输出的输出序列的起始处的字节顺序标记
原文: output the byte order mark at the start of the output sequence |
认可的字节顺序标记
0xfe 0xff
|
UTF-16 big-endian的
|
0xff 0xfe
|
UTF-16 little-endian的
|
0xef 0xbb 0xbf
|
UTF-8(排列顺序)没有影响
|
如果std::consume_header没有选择当读取一个文件开头的字节顺序标记,Unicode字符U + FEFF(零宽度不换行空格)将读取的第一个字符的字符串内容.
原文:
If std::consume_header is not selected when reading a file beginning with byte order mark, the Unicode character U+FEFF (Zero width non-breaking space) will be read as the first character of the string content.
[编辑] 示例
下面的示例演示使用UTF-8 BOM
原文:
The following example demonstrates consuming the UTF-8 BOM
#include <fstream> #include <iostream> #include <string> #include <locale> #include <codecvt> int main() { // UTF-8 data with BOM std::ofstream("text.txt") << u8"\ufeffz\u6c34\U0001d10b"; // read the UTF8 file, skipping the BOM std::wifstream fin("text.txt"); fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf8<wchar_t, 0x10ffff, std::consume_header>)); for(wchar_t c; fin.get(c); ) std::cout << std::hex << std::showbase << c << '\n'; }
输出:
0x7a 0x6c34 0x1d10b
[编辑] 另请参阅
之间进行转换的字符编码,包括UTF-8,UTF-16,UTF-32 原文: converts between character encodings, including UTF-8, UTF-16, UTF-32 (类模板) | |
(C++11) |
之间的转换UTF-8和UCS2/UCS4 原文: converts between UTF-8 and UCS2/UCS4 (类模板) |
(C++11) |
之间的转换UTF-16和UCS2/UCS4 原文: converts between UTF-16 and UCS2/UCS4 (类模板) |
(C++11) |
converts between UTF-8 and UTF-16 (类模板) |