Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main ()
- {
- cout << "Your prefered locale is: " << locale("").name() << endl;
- cout << "Your default locale is: " << locale().name() << endl;
- // you need to imbue wcout with en_US.UTF-8, since fileencoding is en_US.UTF-8, and so these wide characters are too.
- wcout.imbue(locale("en_US.UTF-8") );
- // The full name of Bangkok.
- const string s{"กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์"};
- cout << s << endl;
- // Let's try to convert this.
- mbstate_t mbs;
- char const *p = s.c_str();
- wchar_t wc[s.length()];
- size_t wchars_written = mbsrtowcs(wc,&p,s.length(),&mbs);
- wcout.imbue(locale());
- if (NULL == p) cout << "Problem with mbsrtowcs : " << p << endl;
- else cout << "mbsrtowcs success! number of wchars written: " << wchars_written << endl;
- wcout << "The converted string: " << endl << wc << endl;
- cout << "The converted characters: " << endl ;
- for (auto&& c: wc) wcout << c << L't';
- cout <<endl;
- return 0;
- }
- Your prefered locale is:
- Your default locale is: C
- กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์
- mbsrtowcs success! number of wchars written: 420
- The converted string:
- กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์
- The converted characters:
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Add Comment
Please, Sign In to add comment