未在此范围内声明原始字符串“R”

Raw String ‘R’ was not declared in this scope

本文关键字:字符串 原始 声明 范围内      更新时间:2023-10-16

我正在学习c++,所以请原谅我我正在尝试将原始字符串存储在C++但我得到‘R’ was not declared in this scope这是我的代码

#include <iostream>
#include <string>
int main()
{
    std::string nx =R"('(;<"/  )3-)";
    std::cout << nx;
}

这是一个在线编译器,可以毫无问题地编译它

可能是我在 Ubuntu 15.10 和最新的 G++ 上的编译器 IM 的东西

原始字符串需要 C++11 或以上;如果在联机编译器中选择选项 C++98,则会收到与 g++ 相同的错误。请参阅以下命令以在 g++ 中启用 C++11(取自此 SO 答案,请在适用时投赞成票):

$ g++ -std=c++11 your_file.cpp -o your_program