这在 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";
最佳答案
是的,这是完全有效的。见 here .
另外,来自(草案)标准 2.14.5/4:
A source-file new-line in a raw string literal results in a new-line in the resulting execution string-literal. Assuming no whitespace at the beginning of lines in the following example, the assert will succeed:
const char *p = R"(a\ b c)"; assert(std::strcmp(p, "a\\\nb\nc") == 0);
关于c++ - 在 C++11 中,原始字符串文字可以有多行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22668264/