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

std::codecvt::length

Defined in header <locale>

public: int length( StateT& state, const ExternT* from, const ExternT* from_end, std::size_t max ) const;

(1)

protected: virtual int do_length( StateT& state, const ExternT* from, const ExternT* from_end, std::size_t max ) const;

(2)

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

2%29次尝试转换externT定义的字符数组中的字符。[from, from_end),给定初始转换状态state,最多maxinternT字符,并返回externT这种转换将消耗的字符。修改state仿佛通过执行do_in(state, from, from_end, from, to, to+max, to)对某个想象中的人来说[to, to+max)输出缓冲器

返回值

的数目externT如果转换为do_in()直到所有from_end-from字符被消耗或maxinternT生成字符,或发生转换错误。

非转换专业化std::codecvt<char, char,std::mbstate_t>回报std::min(max, from_end-from)...

二次

代码语言:javascript
复制
#include <locale>
#include <string>
#include <iostream>
 
int main()
{
    //  narrow multibyte encoding
    std::string s = "z\u00df\u6c34\U0001d10b"; // or u8"zß水?"
                      // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
    std::mbstate_t mb = std::mbstate_t();
    std::cout << "Only the first " <<
              std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(
                    std::locale("en_US.utf8")
              ).length(mb, &s[0], &s[s.size()], 2)
              << " bytes out of " << s.size() << " would be consumed "
                 " to produce the first 2 characters\n";
}

二次

产出:

二次

代码语言:javascript
复制
Only the first 3 bytes out of 10 would be consumed to produce the first 2 characters

二次

另见

do_in virtual

converts a string from externT to internT, such as when reading from file (virtual protected member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券