I need a function to convert “explicit” escape sequences into the relative non-printable character.
Es:
char str[] = "\\n";
cout << "Line1" << convert_esc(str) << "Line2" << endl:
would give this output:
Line1
Line2
Is there any function that does this?
I think that you must write such function yourself since escape characters is a compile-time feature, i.e. when you write
"\n"the compiler would replace the\nsequence with the eol character. The resulting string is of length 1 (excluding the terminating zero character).In your case a string
"\\n"is of length 2 (again excluding terminating zero) and contains\andn.You need to scan your string and when encountering
\check the following char. if it is one of the legal escapes, you should replace both of them with the corresponding character, otherwise skip or leave them both as is.( http://ideone.com/BvcDE ):