raw string literals - chunhualiao/public-docs GitHub Wiki
R"( ... )"
-
This is a raw string literal introduced in C++11.
-
Normal string literals (
"..."
) require escaping of special characters:"\n"
for newline"\t"
for tab"\\"
for backslash"\""
for a quote
-
With a raw string literal (
R"( ... )"
), the compiler takes the contents literally, without interpreting escape sequences. -
Newlines, quotes, indentation, and backslashes are all preserved exactly.
Example:
const char* raw = R"(line1
line2 "quoted text" \ no escapes here
)";
👉 In practice, this is often used for:
- Embedding long documentation or help text in source code.
- Storing SQL queries, JSON, or regex patterns.
- Avoiding messy
\n
and\"
in big string literals.