Raw String Literals in C++

Strings in most programming languages can use escape sequences for the new line (‘\n’), backspace (‘\b’), tab (‘\t’) etc. However, there are times when we don’t want them to use such escape sequence characters.

Most languages provide a way not to consume those escape sequences and treat the entire string as raw strings. In C++, we can inform the compiler to treat a string as a raw string by using the following syntax instead of string in plain double quotes.

R"(raw string text)"

For example,

const string RAW_STRING = R"(This is a Raw String with a \t and \n escape sequences which will not be converted)";

Here is a simple Repl that shows how this works:

--

--