C++的字符串常量

  • C++11引入了原始字符串常量,用来减少转义字符的使用。
    • 以R”( )”包裹的字符串称为原始字符串。const char* = R"( tom's name is "tom green")";
    • 示例: ```cpp

      include

      using namespace std;

int main(int argc, char const argv[]) { cout << “传统方式” << endl; const char str = “tom’name is \”tom green\””; cout << str << endl;

cout << “C++11 new方式” << endl; const char *str1 = R”(tom’name is “tom green” \n)”; // Raw cout << str1 << endl;

return 0; } ```