Possible Error in C++ Tututorial

I am wondering if the following, from the Constants page of the C++ language tutorial might be an error:


R"(string with \backslash)"
R"&%$(string with \backslash)&%$"


Both strings above are equivalent to "string with \\backslash". The R prefix
can be combined with any other prefixes, such as u, L or u8.

Should, in the lines directly above, "string with \\backslash" read "string with \backslash" ?
Should, in the lines directly above, "string with \\backslash" read "string with \backslash" ?

No. I see how it could be confusing in context, but the C++ expression "string with \\backslash" is a C++ expression, not prose. It's a string literal, but not a raw string literal.

For example, "\\" has the type char const[2] and the value { '\\', '\0' }, but R"(\\)" has the type char const[3] and the value { '\\', '\\', '\0' }.
however, clang and gcc don't admit '$' as part of the prefix delimiter
error: invalid character '$' in raw string delimiter

(can't find documentation on what else is invalid)
@ne555, there's a GCC bug report that '$' and '@' are not allowed as delimiters in a raw string (2015):
https://gcc.gnu.org/legacy-ml/gcc-bugs/2015-01/msg01267.html

That is probably not the entire list of invalid characters.

Visual Studio 2019 also vomits on '$' and '@' as raw string literal delimiters.
Last edited on
@PeteDD, various compilers probably allowed '$' and '@' when the tutorial was originally written.

Outdated, it is. And very unlikely to be updated.

Raw string literal delimiters are also limited to being less than 16 characters.
https://stackoverflow.com/questions/31818299/why-must-the-delimiters-of-raw-string-literals-be-under-16-chars#31818825

Personally I'd use the delimiters of the first example.


A raw string literal is not the same as a string literal in C++.

String literal "string with \\backslash" is the same as raw string literal R"(string with \blackslash)".

1
2
3
4
5
6
7
#include <iostream>

int main()
{
   std::cout << R"(string with \backslash)" << '\n';
   std::cout << "string with \\backslash" << '\n';
}
Topic archived. No new replies allowed.