fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::string a = "\\u00c1\\u00c4\\u00d3 dsfgdfg";
  8.  
  9. std::wstring ws;
  10. ws.reserve(a.size());
  11.  
  12. size_t start = 0;
  13. do
  14. {
  15. size_t found = a.find("\\u", start);
  16. if (found == std::string::npos) break;
  17.  
  18. if (start < found)
  19. ws.insert(ws.end(), a.begin()+start, a.begin()+found);
  20.  
  21. wchar_t wc = static_cast<wchar_t>(std::stoi(a.substr(found+2, 4), nullptr, 16));
  22. ws.push_back(wc);
  23.  
  24. start = found + 6;
  25. }
  26. while (true);
  27.  
  28. if (start < a.size())
  29. ws.insert(ws.end(), a.begin()+start, a.end());
  30.  
  31. std::wcout << ws.size() << L" " << ws << std::endl;
  32. for(size_t i = 0; i < ws.size(); ++i) {
  33. std::wcout << L"ws[" << i << L"] = " << std::hex << std::setw(4) << std::setfill(L'0') << static_cast<int>(ws[i]) << std::endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
11 ??? dsfgdfg
ws[0] = 00c1
ws[1] = 00c4
ws[2] = 00d3
ws[3] = 0020
ws[4] = 0064
ws[5] = 0073
ws[6] = 0066
ws[7] = 0067
ws[8] = 0064
ws[9] = 0066
ws[a] = 0067