这在C++11下是否合法?
string s = R"(This is the first line
And this is the second line)";
...等同于:
string s = "This is the first line\nAnd this is the second line";
没问题,这是完全有效的。请参见这里。
此外,在(草案)标准2.14.5 / 4中:
原始字符串字面值中的源文件新行会导致执行结果的新行字符串字面值。 假设以下示例中的行开头没有空格,则断言将成功:
const char *p = R"(a\ b c)"; assert(std::strcmp(p, "a\\\nb\nc") == 0);