public member function
int length ( stateT& state, const externT* from, const externT* from_end, size_t max ) const;
Return length of translated sequence
Returns the amount of external characters in the range [from,from_end)
that could be translated into at maximum max
internal characters, as if done with codecvt::in
is also updated as if codecvt::in
was called for a buffer of max
During its operation, this function simply calls the virtual protected member codecvt::do_length
, which is the member function in charge of performing the actions described above.
- State object to keep track of the state of a multibyte character conversion. Typically, this is an object of type mbstate_t.
stateT is the state type (i.e., the third template parameter of codecvt).
- from, from_end
- Pointer to the initial and final characters of the source sequence. The range used is [from,from_end), which contains all the characters between from and from_end, including the character pointed by from but not the character pointed by from_end.
externT is the external character type (i.e., the second template parameter of codecvt).
- Maximum length of the translated sequence (in terms of internal characters).
size_t is an integral type.
The length of the sequence of characters if translated to internal characters.
// codecvt::length example
using namespace std;
int main ()
char origin = "abcdefghijklmnopqrstuvwxyz";
const char * pc;
wchar_t * pwc;
const codecvt<wchar_t,char,mbstate_t>& myfacet =
// calculate length for 10 wchar_t's:
int length = myfacet.length (mystate, origin, origin+sizeof(origin), 10);
wchar_t * dest = new wchar_t[length+1];
myfacet.in (mystate, origin, origin+sizeof(origin), pc, dest, dest+length, pwc);
dest[length]=0; // Terminating null-character
cout << "A string of 10 wchar_t elements: ";
wcout << dest << endl;
A string of 10 wchar_t elements: abcdefghij
- Translate in characters (public member function)
- Return max length of one character (public member function)
- Return length of translated sequence [virtual] (public member function)