fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <iomanip>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. const char* safe_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@/";
  9.  
  10. int main()
  11. {
  12. string str = "C:\\user\\ali baba";
  13. replace(str.begin(), str.end(), '\\', '/');
  14.  
  15. string::size_type pos = 0;
  16. while ((pos = str.find_first_not_of(safe_chars, pos)) != string::npos)
  17. {
  18. ostringstream oss;
  19. oss << '%' << hex << noshowbase << uppercase << (int) str[pos];
  20. string newvalue = oss.str();
  21. str.replace(pos, 1, newvalue);
  22. pos += newvalue.size();
  23. }
  24. str = "file:///" + str;
  25. cout << str;
  26. return 0;
  27. }
Success #stdin #stdout 0s 4352KB
stdin
Standard input is empty
stdout
file:///C:/user/ali%20baba