c++ - 为什么 std::u16cout 不见了?

标签 c++ unicode io c++11

C++03 定义了两种字符类型:charwchar_t。 (让我们忽略 signed charunsigned char 疯狂)。

然后将这两个字符应用于 std::basic_stringstd::basic_ostream 等作为 std::string/std::wstringstd::ostream/std::wostream.

标准库还从流中定义了全局变量 std::coutstd::wcout

新的 c++0x 标准定义了另外两种字符类型 char16_tchar32_t。然而,唯一的新类型定义是 std::u16stringstd::u32string

为什么标准不提供 std::u16ostream?或者 std::u32cout 怎么样?

最佳答案

我们认为实现 Unicode iostream 的工作量太大,不值得: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2238.html

来自论文:

The rationale for leaving out stream specializations of the two new types was that streams of non-char types have not attracted wide usage, so it is not clear that there is a real need for doubling the number of specalizations of this very complicated machinery.

据我了解,标准委员会意识到序列化为宽字符(2 或 4 字节格式)并不常见,在需要 UTF-16 或 UTF-32 的地方,您始终可以使用相同的旧的基于字符的字节流,但具有 codecvt 方面会将您的输入转换为 UTF-16/UTF-32,它可以将其视为另一种多字节格式。

关于c++ - 为什么 std::u16cout 不见了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6020314/

相关文章:

python - 这是确保 python unicode "string"以 utf-8 编码的最佳方法吗?

c++ - 将任意数字输出为 unicode

c++ - 查找并替换文本文件中的字符串并输出到另一个文件

c# - 计算驱动器上的文件数

c++ - 使用 for 循环删除对象数组

c++ - 泄漏内存的不同方式

c++ - 使用 `std::string::c_str` 是否返回动态分配的数组?

javascript - 通过javascript中的正则表达式在单词边界处匹配希伯来语字符?

C++:重载 I/O 运算符

c++ - unicode 窗口中的非 unicode WM_CHAR