使用VScode运行调试C/C++( 二 )


文章插图

2在左侧打开的目次中新建一个 main.cpp 文件 。
新建后点左侧的调试按钮(英文:Debug) , 可以看到 , 今朝没有调试设置装备摆设

使用VScode运行调试C/C++

文章插图

3这时我们需要设置装备摆设本身的调试设置装备摆设 , 回到资本办理器界面 , 我们可以看到目次下多了一个.vscode的文件夹 , 里面有一个launch.json文件 。
我们此刻在这个文件夹中新建一个tasks.json文件 。

使用VScode运行调试C/C++

文章插图

4然后我们需要改写这两个json文件的内容 。
此中launch.json文件内容(此中的miDubuggerPath后的路径要改当作你的mingw编译器的安装路径):
{
"version": "0.2.0",
"configurations": [
{
"name": "Run C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & run file"
},
{
"name": "Debug C/C++",
"type": "cppdbg",
"request": "launch",
【使用VScode运行调试C/C++】"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & debug file"
}
]
}

使用VScode运行调试C/C++

文章插图

5此中tasks.json文件内容(直接复制即可):
{
"version": "2.0.0",
"tasks": [
{
"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "build & run file",
"type": "shell",

推荐阅读