task.json用于g++编译和事后处理
{
"version": "2.0.0",
"tasks": [
{//生成编译文件任务
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",//生成文件的地址
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{ //删除二进制文件任务
"type": "shell",
"label": "delete output file",
"command": "del",
"args": [
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"presentation": {
"reveal": "silent", //删除过程不切换终端(专注程序输出)
}
}
]
}
launch.json用于GDB调试
{
"version": "0.2.0",
"configurations": [
{//进行gdb的过程
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file",//进程gdb之前的工作:生成.exe文件
"postDebugTask": "delete output file" //gdb之后的工作,将二进制文件删除
}
]
}