std::codecvt_byname

来自cppreference.com

 
 
本地化库
语言环境方面
Original:
Locales and facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
locale
字符分类
Original:
Character classification
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
转换
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wstring_convert(C++11)
wbuffer_convert(C++11)
小面类的基类
Original:
Facet category base classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
小面类
Original:
Facet categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
特定于语言环境的方面
Original:
Locale-specific facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代码转换方面
Original:
Code conversion facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
codecvt_utf8(C++11)
codecvt_utf16(C++11)
codecvt_utf8_utf16(C++11)
codecvt_mode(C++11)
C语言环境
Original:
C locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <locale>
template< class internT, class externT, class stateT >
class codecvt_byname : public std::codecvt<internT, externT, stateT>;
std::codecvt_byname是一个std::codecvt方面,它封装了多字节/宽字符转换规则,在其建设一个指定的区域.
Original:
std::codecvt_byname is a std::codecvt facet which encapsulates multibyte/wide character conversion rules of a locale specified at its construction.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
四个专业所提供的标准库
Original:
Four specializations are provided by the standard library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Defined in header <locale>
std::codecvt_byname<char, char, std::mbstate_t>
身份的转换
Original:
identity conversion
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::codecvt_byname<char16_t, char, std::mbstate_t>
UTF-16和UTF-8之间的转换(C++11 起)
Original:
conversion between UTF-16 and UTF-8 (C++11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::codecvt_byname<char32_t, char, std::mbstate_t>
UTF-32和UTF-8(C++11 起)之间的转换
Original:
conversion between UTF-32 and UTF-8 (C++11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::codecvt_byname<wchar_t, char, std::mbstate_t>
区域设置特定的宽字符串和狭窄的,可能是多字节字符串之间的转换
Original:
locale-specific conversion between wide string and narrow, possibly multibyte, string
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 成员函数

构造一个新codecvt_byname方面
Original:
constructs a new codecvt_byname facet
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数)
解构一个codecvt_byname方面
Original:
destructs a codecvt_byname facet
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(受保护的成员函数)

Inherited from std::codecvt

Member types

会员类型
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
intern_type internT
extern_type externT
state_type stateT

Member objects

会员名称
Original:
Member name
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Type
id (静态的) std::locale::id

Member functions

调用do_out
Original:
invokes do_out
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_in
Original:
invokes do_in
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_unshift
Original:
invokes do_unshift
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_encoding
Original:
invokes do_encoding
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_always_noconv
Original:
invokes do_always_noconv
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_length
Original:
invokes do_length
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]
调用do_max_length
Original:
invokes do_max_length
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数of std::codecvt [edit]

Protected member functions

[虚拟的] </ SPAN></div></div>
转换成一个字符串,如写入文件时,从Internt的externT
Original:
converts a string from internT to externT, such as when writing to file
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
将字符串转换,如从文件读取时,从externT到Internt的
Original:
converts a string from externT to internT, such as when reading from file
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
产生的externT不完全转化为字符序列终止符
Original:
generates the termination character sequence of externT characters for incomplete conversion
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
返回的externT需要产生一个Internt的字符的字符数,如果不变
Original:
returns the number of externT characters necessary to produce one internT character, if constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
该方面的测试,如果所有有效参数值的标识转换为编码
Original:
tests if the facet encodes an identity conversion for all valid argument values
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
计算将转换成给定的Internt的缓冲区消耗的externT字符串,该字符串的长度
Original:
calculates the length of the externT string that would be consumed by conversion into given internT buffer
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
[虚拟的] </ SPAN></div></div>
返回的最大数目,可以被转换成一个单一的Internt的字符externT字符
Original:
returns the maximum number of externT characters that could be converted into a single internT character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]


</div>

Inherited from std::codecvt_base

会员类型
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
enum result { ok, partial, error, noconv };
无作用域的枚举类型
Original:
Unscoped enumeration type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
枚举常量
Original:
Enumeration constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
ok
转换完成,没有错误
Original:
conversion was completed with no error
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
partial
不是所有的源字符被转换了
Original:
not all source characters were converted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
error
遇到无效的字符
Original:
encountered an invalid character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
noconv
没有转换,输入和输出类型是相同的
Original:
no conversion required, input and output types are the same
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 为例

这个例子演示了读取的GB18030编码的文件,从GB18030-意识到语言环境使用的的codecvt方面
Original:
This example demonstrates reading a GB18030-encoded file using the codecvt facet from a GB18030-aware locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <fstream>
#include <string>
#include <locale>
int main()
{
    // GB18030 narrow multibyte encoding
    std::ofstream("text.txt") << "\x7a"              // letter 'z', U+007a
                                 "\x81\x30\x89\x38"  // letter 'ß', U+00df
                                 "\xcb\xae"          // CJK ideogram '水' (water), U+6c34
                                 "\x94\x32\xbc\x35"; // musical sign '𝄋' (segno), U+1d10b
    std::wifstream fin("text.txt");
    fin.imbue(std::locale(fin.getloc(),
              new std::codecvt_byname<wchar_t, char, std::mbstate_t>("zh_CN.gb18030")));
    for(wchar_t c; fin.get(c); )
        std::cout << std::hex << std::showbase << c << '\n';
}

Output:

0x7a
0xdf
0x6c34
0x1d10b

[编辑] 另请参阅

之间进行转换的字符编码​​,包括UTF-8,UTF-16,UTF-32
Original:
converts between character encodings, including UTF-8, UTF-16, UTF-32
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(类模板) [edit]

来自“http://zh.cppreference.com/mwiki/index.php?title=cpp/locale/codecvt_byname&oldid=28412