fork(12) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4.  
  5. std::string wstring_from_bytes(std::wstring const& wstr)
  6. {
  7. std::size_t const size = sizeof(wstr.c_str());
  8. char *str = new char[size];
  9. std::string temp;
  10.  
  11. std::wcstombs(str, wstr.c_str(), size);
  12.  
  13. temp = str;
  14.  
  15. return temp;
  16. }
  17.  
  18. int main()
  19. {
  20. std::wstring wstr = L"abcd";
  21. std::string str = wstring_from_bytes(wstr);
  22.  
  23. std::cout << str;
  24. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
abcd