How to make a C ++ source string that includes an raw string terminator?

I use R"(...)"to determine the raw string, but if the string really contains a string string delimiter )", the compiler will complain.

For instance:

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

How can I change this to make it work?

+4
source share
1 answer

The syntax for a string literal of a string is something like this:

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

An extra separator next to the parentheses exists for exactly the reason you just stumbled. This will allow you to include string control characters in the string. So add a separator:

auto tag = R"tag("("add")")tag"; 
+8
source

Source: https://habr.com/ru/post/1696242/


All Articles