length
描述 (Description)
它返回[from,from_end]范围内可以转换为最大内部字符数的外部字符数,输出就像应用codecvt :: in一样。
声明 (Declaration)
以下是std :: ctype :: length的声明。
C++98
int length (state_type& state, const extern_type* from,
const extern_type* from_end, size_t max) const;
C++11
int length (state_type& state, const extern_type* from,
const extern_type* from_end, size_t max) const;
参数 (Parameters)
state - 它是一个状态对象。
from, from_end - 用于查找源序列的初始和最终字符。
max - 用于查找已翻译序列的最大长度。
返回值 (Return Value)
它根据翻译的内部字符返回字符序列的长度。
异常 (Exceptions)
No-throw guarantee - 即使抛出异常,也不会抛出异常,facet对象中没有变化。
数据竞争 (Data races)
访问构面对象。
例子 (Example)
在下面的例子中解释了std :: ctype :: length。
#include <iostream>
#include <locale>
#include <cwchar>
#include <cstddef>
int main () {
typedef std::codecvt<wchar_t,char,std::mbstate_t> facet_type;
std::locale loc;
const facet_type& myfacet = std::use_facet<facet_type>(loc);
const char source[] = "sairamkrishna mammahe";
std::mbstate_t mystate;
const char * pc;
wchar_t * pwc;
std::size_t length = myfacet.length (mystate, source, source+sizeof(source), 30);
wchar_t* dest = new wchar_t[length];
myfacet.in (mystate, source, source+sizeof(source), pc, dest, dest+length, pwc);
std::wcout << dest << std::endl;
delete[] dest;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
sairamkrishna mammahe