fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <locale>
  4. #include <codecvt>
  5. #include <iomanip>
  6.  
  7. int main() {
  8. // широкие символы
  9. std::wstring wstr = L"Я строка в UCS-2. がダウンロードできません";
  10. // широкие символы в UTF-8
  11. std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
  12. std::cout << "Chr | UTF-8\n============\n";
  13. for(const auto &c:wstr) {
  14. std::string u8str = conv.to_bytes(c);
  15. std::cout << u8str << " : ";
  16. for(const uint8_t &i:u8str)
  17. std::cout << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(i) << ' ';
  18. std::cout << std::dec << '\n';
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Chr | UTF-8
============
Я   : d0 af 
    : 20 
с   : d1 81 
т   : d1 82 
р   : d1 80 
о   : d0 be 
к   : d0 ba 
а   : d0 b0 
    : 20 
в   : d0 b2 
    : 20 
U   : 55 
C   : 43 
S   : 53 
-   : 2d 
2   : 32 
.   : 2e 
    : 20 
が   : e3 81 8c 
ダ   : e3 83 80 
ウ   : e3 82 a6 
ン   : e3 83 b3 
ロ   : e3 83 ad 
ー   : e3 83 bc 
ド   : e3 83 89 
で   : e3 81 a7 
き   : e3 81 8d 
ま   : e3 81 be 
せ   : e3 81 9b 
ん   : e3 82 93