Skip to content

Instantly share code, notes, and snippets.

@Cornpop456
Created June 20, 2022 13:53
Show Gist options
  • Save Cornpop456/fac70084b5d99c01194638ce5c2554da to your computer and use it in GitHub Desktop.
Save Cornpop456/fac70084b5d99c01194638ce5c2554da to your computer and use it in GitHub Desktop.
#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