It returns the number of external characters in the range [from,from_end) that could be translated into at maximum of max internal characters, output as if applying codecvt::in.
DeclarationFollowing is the declaration for std::ctype::length.
C++98int 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 − It is a state object.
from, from_end − It used to find an initial and final characters of the source sequence.
max − It is used to find maximum length of the translated sequence.
It returns the length of the sequence of characters, in terms of translated internal characters.
ExceptionsNo-throw guarantee − never throws exceptions even if an exception is thrown, there are no changes in the facet object.
Data racesThe facet object is accessed.
ExampleIn below example explains about 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; }
Let us compile and run the above program, this will produce the following result −
sairamkrishna mammahe
locale.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4