c++ - 在 C++11 中,原始字符串文字可以有多行吗?

标签 c++ string c++11

这在 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/

相关文章:

c++ - 如何在不增加 vector 大小的情况下保留多维 vector ?

c++11 - "&"和 std::reference_wrapper 之间的区别?

c++ - Objective C 的 Xcode 6 上出现错误 'Undefined symbols for architecture x86_64 '

c++ - 如何强制编译器识别模板函数中的 lambda 类型?

Java 将字符串转换为十进制(ASCII)?

java - 制定 Intent ,作为 Activity 的一部分?

c++ - MS Visual Studio 2013 上的 std::reference_wrapper

c++ - C++ 类中的标记区域

c++ - 有没有一种更快的方法来按位连接两个整数?

java - java中检查字符串是否为null