之前已经写过vscode配置c++环境的方式,在使用过程中,发现现在的编译方式没有支持c++11的新特性,通过配置支持c++11
g++ --version
g++ -std=c++11 test_c11.cpp
在配置c++编译环境时,有3个配置文件,launch.json文件对应的name即选择编译时对应的编译配置。
找到当前选择的配置,找到对应的item
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"environment": [],
"externalConsole": false, // true则弹出终端,false会在下方terminal直接输出
"MIMode": "gdb",
// 这里的路径需要修改。改成自己的路径
"miDebuggerPath": "xxxxxxx/gdb.exe",
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
在tasks.json文件下找到preLaunchTask项
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
....
},
"tasks": [....
]
添加配置
在args中添加 -std=c++11
配置,尝试了一下,需要填在生成的文件之后
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
"-std=c++11"
],
"problemMatcher": {
....
},
"tasks": [....
]
https://blog.csdn.net/qq_21397217/article/details/51171964