VSCode调试C++需要的配置。其中修改了launch.json和task.json文件。该设置用于编译当前文件,在工程文件夹下生成a.out可执行文件。
如果需要编译和单步调试多个文件工程,可以写Makefile.txt或者CMakeLists.txt文件,生成可调式的可执行文件后,对可执行文件进行单步调试。
launch.json
修改了
"program": "${workspaceFolder}/a.out",
"preLaunchTask": "g++",
修改后如下:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "g++",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o",
"${workspaceRoot}/a.out"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}