Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make C++ raw string which includes raw string terminator?

I use R"(...)" to define a raw string but, if the string actually contains a raw string terminator )", the compiler will complain.

For example:

auto tag = R"("(add)")"; // try to get string <"(add)">

How can I modify this so it works?

like image 363
freyone Avatar asked Apr 17 '18 04:04

freyone


1 Answers

The syntax for a raw string literal is something like the following:

R"<delim>(...)<delim>"

The optional delimiter that is next to the parentheses is there exactly for the reason you just stumbled upon. It's to let you include the raw string's control characters inside the literal. So add a delimiter:

auto tag = R"tag("("add")")tag"; 
like image 125
StoryTeller - Unslander Monica Avatar answered Oct 03 '22 20:10

StoryTeller - Unslander Monica