在c++ 11中,原始字符串字面值可以有多行
In C++11, can raw string literals have multiple lines?
这在c++ 11下合法吗?
string s = R"(This is the first line
And this is the second line)";
…相当于:
string s = "This is the first linenAnd this is the second line";
是的,这完全有效。看到这里。
同时,从(草案)标准2.14.5/4:
原始字符串字面值中的源文件new-line将产生一个新行在结果执行中字符串字面值。的行开始处没有空白下面的例子,断言将成功:
const char *p = R"(a b c)"; assert(std::strcmp(p, "a\nbnc") == 0);
相关文章:
- 为什么添加两个字符串字面值不使用操作符+
- 在编译时定义字符串/char字面值
- c++的字符串字面值如何存储在内存中?
- 为什么可以向字符串字面值添加整数?
- 可修改字符串字面值的用例
- c++ constexpr vs宏,字符串字面值vs整数
- 字符串对字符串字面值的优化不够
- 是否有可能合法地重载字符串字面值和const char*
- UnicodeString /字符串字面值vs十六进制值
- 为什么将指针的内容修改为字符串字面值是错误的?
- c++: Std::cout缓冲区错误?对字符串变量和字符串字面值使用std::cout导致输出混乱
- C/ c++预处理器中的宏参数字符串化为宽字符串字面值
- 是否有可能获得包含字面值的字符串的长度
- 试图对初始化为字符串字面值的char指针的未定义行为进行推理
- 如何从字符串字面值初始化无符号字符数组
- 为什么空字符串字面值被视为真?
- 将字符串字面值的第一个字符赋值给字符数组将赋值整个字符串字面值
- 如何在c++中连接字面值字符串和宏到有效的字符串
- 将传递的参数限制为字符串字面值
- 将字符串数组放入参数中,然后将元素与字面值字符串进行比较