C ++ std :: ctype< char> :: widen()的作用是什么? [英] C++ What is the role of std::ctype<char>::widen()?

查看:53
本文介绍了C ++ std :: ctype< char> :: widen()的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据C ++标准(C ++ 17草案(N4659)的第30.7.5.2.4条), out<<如果 ch char 并且 out std :: ostream .

According to the C++ standard (§30.7.5.2.4 of C++17 draft (N4659)), out << ch will not perform a widening operation on ch, if ch is a char and out is a std::ostream.

这是否意味着保证 std :: ctype< char> :: widen()(即 char -> char )按标准是对基本源字符集中的所有字符的标识函数( widen(ch)== ch )?

Does this imply that std::ctype<char>::widen() (i.e., char -> char) is guaranteed by the standard to be an identity function (widen(ch) == ch) for all characters in the basic source character set?

如果是这样,这是否意味着标准要求所有语言环境都使用来自基本源字符集的字符的相同非宽度(或多字节)编码?

If so, does this, in turn, imply that all locales are required by the standard to use the same non-wide (or multi-byte) encoding of characters from the basic source character set?

如果不是,则好像是 out<<'x',对于文字有特殊的字符编码选择,即使在某些语言环境中也可能无法在所有语言环境中使用.也就是说,可能没有选择字符文字编码的方式,例如 out<<'x'同时在所有语言环境中起作用.

If not, it seems like out << 'x', with a particular choice of character encoding for literals, might not work in all locales, even when it works in some. That is, there might be no choice of character literal encoding, such that out << 'x' works in all locales simultaneously.

推荐答案

不,它只是说

template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, char c);

其中流和<< 运算符都使用相同的 char 类型进行交易,则不进行转换.

where both the stream and the << operator trades in the same char type there is no conversion.

如果 c 的类型为 char ,并且流的字符类型不是 char ,则seq包含 out.widen(c);否则seq由 c 组成.

If c has type char and the character type of the stream is not char, then seq consists of out.widen(c); otherwise seq consists of c.

在所有其他情况下,可以使用语言环境来选择性地转换字符,而对语言环境的作用没有任何限制.

In all other cases the locale is used to optionally transform the character with no restrictions on what the locales might do.

这篇关于C ++ std :: ctype&lt; char&gt; :: widen()的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆