std::codecvt::encoding
STD::codecvt::编码,做[医]编码
Defined in header | | |
---|---|---|
public: int encoding() const; | (1) | |
protected: virtual int do_encoding() const; | (2) | |
1%29公共成员函数,调用成员函数。do_encoding
最派生的类。
2%29如果由此codecvt facet表示的编码将每个内部字符映射到相同的外部字符数,则返回该数字。如果编码是可变长度%28例如。UTF-8或UTF-1
6%29,返回0
如果编码与状态相关,则返回-1
...
返回值
的确切数目externT
对应于一个字符的字符internT
人物,如果是常量的话。0
如果数字有变化,-1
如果编码是状态依赖的。
非转换专业化std::codecvt<char, char,std::mbstate_t>回报1...
例外
(none) | (until C++11) |
---|---|
noexcept specification: noexcept | (since C++11) |
例
二次
#include <locale>
#include <iostream>
int main()
{
std::cout << "en_US.utf8 is a variable-length encoding, encoding() returns "
<< std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
std::locale("en_US.utf8")
).encoding() << '\n';
std::cout << "zh_CN.gb18030 is also variable-length, encoding() == "
<< std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
std::locale("zh_CN.gb18030")
).encoding() << '\n';
std::cout << "ru_RU.koi8r is a single-byte encoding encoding() == "
<< std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
std::locale("ru_RU.koi8r")
).encoding() << '\n';
}
二次
产出:
二次
en_US.utf8 is a variable-length encoding, encoding() returns 0
zh_CN.gb18030 is also variable-length, encoding() == 0
ru_RU.koi8r is a single-byte encoding encoding() == 1
二次
另见
MB_CUR_MAX | maximum number of bytes in a multibyte character in the current C locale(macro variable) |
---|---|
do_max_length virtual | returns the maximum number of externT characters that could be converted into a single internT character (virtual protected member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。