首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::codecvt::max_length

Defined in header <locale>

?

?

public: int max_length() const;

(1)

?

protected: virtual int do_max_length() const;

(2)

?

1%29公共成员函数,调用成员函数do_max_length最派生的类。

2%29返回最大值do_length(state, from, from_end, 1)可以返回任何有效范围。[from, from_end)任何有效的state...

返回值

最大数目ExternT转换时可以使用的字符。in()生产一个InternT性格。

非转换专业化std::codecvt<char, char,std::mbstate_t>回报1...

注记

如果编码是状态相关的%28encoding() == -1%29,然后超过max_length()外部字符可以被消耗以产生一个内部字符。

例外

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

二次

代码语言:javascript
复制
#include <locale>
#include <iostream>
#include <codecvt>
 
int main()
{
    std::cout << "In codecvt_utf8, the longest multibyte character is "
              << std::codecvt_utf8<wchar_t>().max_length() << " bytes long\n";
 
    std::cout << "In header-consuming codecvt_utf8, the longest multibyte character is "
              << std::codecvt_utf8<wchar_t,
                                   0x10ffff,
                                   std::consume_header>().max_length() << " bytes long\n";
 
    std::cout << "In this system's en_US.utf8, the longest multibyte character is "
              << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
                    std::locale("en_US.utf8")
              ).max_length() << " bytes long\n";
 
    std::cout << "In this system's zh_CN.gb18030, the longest multibyte character is "
              << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
                    std::locale("zh_CN.gb18030")
              ).max_length() << " bytes long\n";
}

二次

产出:

二次

代码语言:javascript
复制
In codecvt_utf8, the longest multibyte character is 4 bytes long
In header-consuming codecvt_utf8, the longest multibyte character is 7 bytes long
In this system's en_US.utf8, the longest multibyte character is 6 bytes long
In this system's zh_CN.gb18030, the longest multibyte character is 4 bytes long

二次

另见

MB_CUR_MAX

maximum number of bytes in a multibyte character in the current C locale(macro variable)

do_encoding virtual

returns the number of externT characters necessary to produce one internT character, if constant (virtual protected member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com