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?
String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes).
Raw string literal in C++ C++Server Side ProgrammingProgramming. In C++11 and above there is a concept called Raw string. In strings we use different characters like \n, \t etc. They have different meaning. The \n is used to return the cursor to the next line, the \t generates a tab etc.
A raw string in programming allows all characters in a string literal to remain the same in code and in the material, rather than performing their standard programming functions. Raw strings are denoted with the letter r, or capital R, and might look something like this: R “(hello)”
A Literal is a constant variable whose value does not change during the lifetime of the program. Whereas, a raw string literal is a string in which the escape characters like ' \n, \t, or \” ' of C++ are not processed. Hence, a raw string literal that starts with R”( and ends in )”.
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)")~";
The raw string will terminate after the first )"
it sees. You can change the delimiter to ***
for example:
string raw_str = R"***(R"(foo)")***";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With