VScode C++程序配置文档
首先给一下大佬的链接:https://www.jianshu.com/p/2700f2b93b14
然后记录一下自己的配置文档
注释的那个每次使用要修改,而下面的那个无需修改
- tasks.json
// {
// "version": "2.0.0",
// "tasks": [
// {
// "label": "build",
// "type": "shell",
// "command": "g++",
// "args":[
// "-g","test.cpp","-o","test"
// ],
// "group": {
// "kind": "build",
// "isDefault": true
// }
// }
// ]
// }
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build", //相当与名字,与后面launch.json中preLaunchTask参数要保持一致
"type": "shell",
"command": "g++",
"args": [ //编译所需要的参数,包括编译方式,源文件,和生成的可执行文件
"-g",
"-Wall",
"-std=c++17",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"presentation": { //控制终端显示
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
},
{
"label": "run",
"type": "shell",
"dependsOn": ["build"], //依赖的配置,运行之前需要编译链接形成可执行文件
"command": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"presentation": { //控制终端显示
"echo": false, // 执行命令是否输出到集成终端
"reveal": "always",
"focus": false,
"panel": "shared", //控制是否共享面板
"showReuseMessage": false, //是否显示"终端终端将被重用,是否显示"的提示
"clear": true //执行任务前是否清除终端
},
//"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
- launch.json
// {
// "version": "0.2.0",
// "configurations": [
// {
// "name": "(gdb) Launch",
// "type": "cppdbg",
// "request": "launch",
// "program": "${workspaceFolder}/test",
// "args": [],
// "stopAtEntry": false,
// "cwd": "${workspaceFolder}",
// "environment": [],
// "externalConsole": true,
// "MIMode": "gdb",
// "preLaunchTask": "build",
// "setupCommands": [
// {
// "description": "Enable pretty-printing for gdb",
// "text": "-enable-pretty-printing",
// "ignoreFailures": true
// }
// ]
// }
// ]
// }
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}", //程序可执行文件的路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //设为false时使用集成终端,true为外置终端
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe"//windows系统下要更新相应的路径
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}