原生字符串字面值

原生字符串字面值(raw string literal)使用户书写的字符串所见即所得。C++11中原生字符串的声明相当简单,只需在字符串前加前缀“R”,并在引用中使用括号左右标识。

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <string>
using namespace std;

int () {
cout << R"(Hello, n everyone.)" << endl;
string str = R"(I am
IAJAOP, 24
years old.n)";
cout << str << endl;

return 0;
}

输出结果为:

1
2
3
4
Hello, n everyone.
I am
IAJAOP, 24
years old.n