21
  string raw_str = R"(R"(foo)")";

If I have R"()" inside a raw string, and that causes the parser to confuse. (ie., it thought the left most )" was the end of the raw string.

How do I escape this?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
One Two Three
  • 22,327
  • 24
  • 73
  • 114
  • 1
    Possible duplicate of [Include )" in raw string literal without terminating said literal](https://stackoverflow.com/questions/30308088/include-in-raw-string-literal-without-terminating-said-literal) – Mihayl Mar 22 '18 at 10:08

2 Answers2

37

The format for the raw-string literals[2] is: R"delimiter( raw_characters )delimiter"

so you can use a different delimiter that is not in the string like:

string raw_str = R"~(R"(foo)")~";
Mihayl
  • 3,821
  • 2
  • 13
  • 32
12

The raw string will terminate after the first )" it sees. You can change the delimiter to *** for example:

string raw_str = R"***(R"(foo)")***";
wally
  • 10,717
  • 5
  • 39
  • 72