在线文档教程
C++
本土化 | Localizations

std::codecvt::length

STD::codecvt::长度,做[医]长度

Defined in header
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)...

二次

#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"; }

二次

产出:

二次

Only the first 3 bytes out of 10 would be consumed to produce the first 2 characters

二次

另见

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

© cppreference.com

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

http://en.cppreference.com/w/cpp/locale/codecvt/ength