char str[] = "C:\Windows\system32"
auto raw_string = convert_to_raw(str);
std::cout << raw_string;
Desired output:
C:\Windows\system32
Is it possible? I am not a big fan of cluttering my path strings with extra backslash. Nor do I like an explicit R"()" notation.
Any other work-around of reading a backslash in a string literally?
That's not possible,
\has special meaning inside a non-raw string literal, and raw string literals exist precisely to give you a chance to avoid having to escape stuff. Give up, what you need isR"(...)".Indeed, when you write something like
you can verify yourself that
strlen(str)is 3, not 4, which means that once you compile that line, in the binary/object file there's only one single character, the newline character, corresponding to\n; there's no\nornanywere in it, so there's no way you can retrieve them.As a personal taste, I find raw string literals great! You can even put real Enter in there. Often just for the price of 3 characters -
R,(, and)- in addtion to those you would write anyway. Well, you would have to write more characters to escape anything needs escaping.Look at
That's 28 keystrokes from
Rto last"included, and you can see in a glimpse it's 6 lines.The equivalent non-raw string
is 30 keystrokes from
Rto last"included, and you have to parse it carefully to count the lines.A pretty short string, and you already see the advantage.