26
 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?

1

2 Answers 2

40

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)")~"; 
Sign up to request clarification or add additional context in comments.

Comments

16

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.