Janik Zikovsky Janik Zikovsky - 1 year ago 134
C++ Question

In C++11, can raw string literals have multiple lines?

Is this legal under C++11?

string s = R"(This is the first line
And this is the second line)";

... being equivalent to:

string s = "This is the first line\nAnd this is the second line";

Answer Source

Yes, that is perfectly valid. See here.

Also, from the (draft) standard:

A source-file new-line in a raw string literal results in a new-line in the resulting execution string-literal, unless preceded by a backslash. Assuming no whitespace at the beginning of lines in the following example, the assert will succeed:

const char *p = R"DELIM(a\
assert(std::strcmp(p, "a\\\nb\nc") == 0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download