escape R"()" in a raw string in C++

One Two Three picture One Two Three · Mar 21, 2018 · Viewed 12.1k times · Source
  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?

Answer

Mihayl picture Mihayl · Mar 21, 2018

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)")~";