Created
June 20, 2022 13:53
-
-
Save Cornpop456/fac70084b5d99c01194638ce5c2554da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
string line; | |
getline(cin, line); | |
bool escape = false; | |
string escaped = ""; | |
for (char c : line) { | |
if (c == '\\' && !escape) { | |
escape = true; | |
continue; | |
} | |
if (escape && c == 'n') { | |
escaped += '\n'; | |
} else if (escape && c == 't') { | |
escaped += '\t'; | |
} else if (escape && c == '"') { | |
escaped += '\"'; | |
} else if (escape && c == '\\') { | |
escaped += '\\'; | |
} else { | |
if (escape) { | |
cout << "wrong escape!" << endl; | |
exit (EXIT_FAILURE); | |
} | |
escaped += c; | |
} | |
escape = false; | |
} | |
if (escape) { | |
cout << "wrong escape!" << endl; | |
exit (EXIT_FAILURE); | |
} | |
cout << escaped << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment