fork(12) download
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. string unescape(const string& s)
  6. {
  7. string res;
  8. string::const_iterator it = s.begin();
  9. while (it != s.end())
  10. {
  11. char c = *it++;
  12. if (c == '\\' && it != s.end())
  13. {
  14. switch (*it++) {
  15. case '\\': c = '\\'; break;
  16. case 'n': c = '\n'; break;
  17. case 't': c = '\t'; break;
  18. // all other escapes
  19. default:
  20. // invalid escape sequence - skip it. alternatively you can copy it as is, throw an exception...
  21. continue;
  22. }
  23. }
  24. res += c;
  25. }
  26.  
  27. return res;
  28. }
  29.  
  30. int main()
  31. {
  32. string s;
  33. cin >> s;
  34. cout << unescape(s) << endl;
  35. }
Success #stdin #stdout 0s 2860KB
stdin
dimka\ndurak
stdout
dimka
durak