fork download
  1. #include <string>
  2. #include <locale>
  3. #include <codecvt>
  4. #include <iostream>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. std::string str("\x61\x61\x61\xf0\x9f\x98\xa8\xe4\xb8\xad\xe6\x96\x87");
  12.  
  13. std::wstring_convert<std::codecvt_utf8<wchar_t> > cvt_utf8;
  14. std::wstring ws = cvt_utf8.from_bytes(str);
  15.  
  16. wcout << L"size of wchar_t == " << sizeof(wchar_t) << endl;
  17. wcout << L"ws.len == " << ws.length() << endl;
  18. wcout << L"ws: " << ws << endl;
  19.  
  20. for (int i = 0; i < ws.length(); i++)
  21. {
  22. wcout << L"0x" << hex << (int)ws[i] << L" ";
  23. }
  24. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
size of wchar_t == 4
ws.len == 6
ws: aaa???
0x61 0x61 0x61 0x1f628 0x4e2d 0x6587