1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// codecvt::length example
#include <iostream>
#include <locale>
using namespace std;
int main ()
{
locale loc;
mbstate_t mystate;
char origin[] = "abcdefghijklmnopqrstuvwxyz";
const char * pc;
wchar_t * pwc;
const codecvt<wchar_t,char,mbstate_t>& myfacet =
use_facet<codecvt<wchar_t,char,mbstate_t> >(loc);
// 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;
return 0;
}
|