用的是vs code,是一个新手,在C++ primer plus上看到了原始字符串,但是自己却无法操作,很迷茫,呜呜~~~
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "I print \'\\\', \"\\n\" as I like." << endl;
cout << R"(I print '\', "\n" as I like.)" << endl;
cout << R"(I print '\',
"\n" as I like.)" << endl;
cout << R"haha(I print '\', "\n" and )" as I like.)haha" << endl;
}
try9.cpp:10:14: error: expected ';' after expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
;
try9.cpp:10:13: error: use of undeclared identifier 'R'
cout << R"(I print '', "\n" as I like.)" << endl;
^
try9.cpp:10:30: error: expected ';' after expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
;
try9.cpp:10:14: warning: expression result unused [-Wunused-value]
cout << R"(I print '', "\n" as I like.)" << endl;
^~~~~~~~~~~~~~~~
try9.cpp:10:30: error: expected expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
try9.cpp:11:14: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << R"(I print '',
^
try9.cpp:11:14: error: expected ';' after expression
cout << R"(I print '',
^
;
try9.cpp:11:13: error: use of undeclared identifier 'R'
cout << R"(I print '',
^
try9.cpp:11:14: error: expected expression
cout << R"(I print '',
^
try9.cpp:12:25: warning: missing terminating '"' character [-Winvalid-pp-token]
"\n" as I like.)" << endl;
^
try9.cpp:13:60: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << R"haha(I print '', "\n" and )" as I like.)haha" << endl;
^
4 warnings and 7 errors generated.
试着改了一下C++的版本,试了C++11以及更高的C++20,但是没有用。
呜呜呜~~~怎么才能正常运行呢,本小白要疯了。呜呜呜~~~
你用的是什么编译器?你得打开C++11编译选项。如果是g++的话,用g++ -std=c++11
,用msvc的话,用cl /std:c++11
代码没有问题,我用vscode直接可以运行。并没有去设置c++版本的。
手动编译命令g++ te.cpp -o tess
和.\tess
。
也可以安装一个run code
点右上角图标直接编译运行
如果其他程序运行正常,只有这个原始字符串运行出错的话,可以代码是不是有什么语法错误,再有就是看看环境配置是否正确,另外,Mac运行C++脚本,不用单独配置环境,vs code下载Code Runner就行了
task.json
编码规范不同吧,需要更新c的标准,版本过低是不支持这些特性的
c++ 开发最好用 clion 开发工具,搜索jeatbean 全家筒
题主,首先你先要确定下你本机有没有装MinGW
1、没有的话请下载:
下载地址:https://sourceforge.net/projects/mingw-w64/files/
下载的文件:进入网站后不要点击 "Download Lasted Version",往下滑,找到最新版的 "x86_64-posix-seh"。
安装MinGW:下载后是一个7z的压缩包,解压后移动到你想安装的位置即可。我的安装位置是:D:\2Software\mingw64
2、安装完MinGW后,要看下你又没没有配置环境变量:
把你刚刚安装MinGW的路径拷贝一下
配置环境变量:在path下新建
编辑一下task json文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++", //修改此项
"command": "D:\2Software\mingw64\bin\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\2Software\mingw64\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
转义有点乱
上图:
需要安装插件
你没有进c++环境吧