Guest User

Untitled

a guest
Jul 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6. cout << "Your prefered locale is: " << locale("").name() << endl;
  7. cout << "Your default locale is: " << locale().name() << endl;
  8.  
  9. // you need to imbue wcout with en_US.UTF-8, since fileencoding is en_US.UTF-8, and so these wide characters are too.
  10. wcout.imbue(locale("en_US.UTF-8") );
  11.  
  12. // The full name of Bangkok.
  13. const string s{"กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์"};
  14. cout << s << endl;
  15.  
  16. // Let's try to convert this.
  17. mbstate_t mbs;
  18. char const *p = s.c_str();
  19. wchar_t wc[s.length()];
  20. size_t wchars_written = mbsrtowcs(wc,&p,s.length(),&mbs);
  21.  
  22. wcout.imbue(locale());
  23. if (NULL == p) cout << "Problem with mbsrtowcs : " << p << endl;
  24. else cout << "mbsrtowcs success! number of wchars written: " << wchars_written << endl;
  25.  
  26. wcout << "The converted string: " << endl << wc << endl;
  27. cout << "The converted characters: " << endl ;
  28. for (auto&& c: wc) wcout << c << L't';
  29. cout <<endl;
  30. return 0;
  31. }
  32.  
  33. Your prefered locale is:
  34. Your default locale is: C
  35. กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์
  36. mbsrtowcs success! number of wchars written: 420
  37. The converted string:
  38. กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์
  39. The converted characters:
  40. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Add Comment
Please, Sign In to add comment