I want to embed certain signals within a string literal in the same style as “\n” and “\a”. My program looks at the string, sees the escape character, and then acts depending on the character following it.
The problem however is that C++, as part of it’s compilation process, resolves anything using “\” as the escape character. In addition, the C standard library, which I use frequently, uses “%” as an escape character too.
So both “\” and “%” can’t be used. The forward slash “/” looks too similar to “\”, and for the moment, most other characters are either too commonly used, or do not give the appearance of an escape.
My question is, what is the best character to use as an escape character, that does not collide with common C++ string utilities that rely on their own escaping character. “Best” in this sense, would objectively describe a character that is used infrequently in normal dialog and mathematics, and is readily identifiable as an escape at a glance.
There’s no reason why you can’t escape your backslashes (e.g.
\\n). If you find that ugly to type, try raw string literals from C++11:Note that the parentheses are not part of the string. If your string is going to contain
)"you can put your own delimiter before the opening parenthesis, which must follow the closing paranthesis: