C++ 原生字符串编译报错如何处理?

2018-09-13 12:43:09 +08:00
 coool

如图,请问如何解决? 代码:

#include <iostream> #include <string> using namespace std;</string></iostream>

int main() { cout << R "(C:\file)";

return 0;

}

报错: 2-1-1.cpp: In function ‘ int main()’: 2-1-1.cpp:7:13: error: ‘ R ’ was not declared in this scope cout << R "(C:\file)";

2212 次点击
所在节点    C
6 条回复
wevsty
2018-09-13 12:54:32 +08:00
什么编译器?
R 这种原始字符串语法只有支持 C++11 以上标准的编译器才能使用。

MSVC 必须得 2010 以上版本。

g++需要添加-std=c++11 这样的参数才支持的
wevsty
2018-09-13 12:56:57 +08:00
补充一下
https://msdn.microsoft.com/en-us/library/hh567368.aspx
如果是 MSVC 的话根据 MSDN
raw string 这个语法必须得是 Visual Studio 2013 以上才能支持。
chingyat
2018-09-13 15:42:01 +08:00
R 和 “ 之间不要加空格。
coool
2018-09-13 16:02:57 +08:00
@chingyat 您好,非常感谢,确实是不能加空格,另外我用的楼上的 g++,增加了 -std=c++11 编译成功了。
coool
2018-09-13 16:04:08 +08:00
@wevsty 您好,非常感谢指导!我用的 g++,增加了-std=c++11 参数另外去掉了 R 和引号之间的空格,编译成功了。谢谢。
FrankHB
2018-09-16 06:36:05 +08:00
你用的什么古董 g++,g++6 开始默认-std=gnu++14。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/488899

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX