fork(1) 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(int argc, wchar_t* argv[])
  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_utf16<wchar_t> > cvt_utf8;
  14. auto 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.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
size of wchar_t == 4
ws.len == 7
0x6100 0x6100 0x6100 0x3dd8 0x28de 0x2d4e 0x8765