这在C++ 11下是合法的吗?
string s = R"(This is the first line
And this is the second line)";
Run Code Online (Sandbox Code Playgroud)
......相当于:
string s = "This is the first line\nAnd this is the second line";
Run Code Online (Sandbox Code Playgroud)
Fer*_*cio 36
是的,这完全有效.看到这里.
另外,根据(草案)标准2.14.5/4:
原始字符串文字中的源文件换行符会在生成的执行字符串文字中生成换行符.假设在以下示例中的行的开头没有空格,则断言将成功:
Run Code Online (Sandbox Code Playgroud)const char *p = R"(a\ b c)"; assert(std::strcmp(p, "a\\\nb\nc") == 0);