部分內容來源於:
1. launch.json
需要修改的地方:launch中 "miDebuggerPath" 選項需要設置為你的調試器(gdb.exe)所在位置 這里的是我電腦上MinGW -w64的安裝位置
無論安裝的是MinGW還是mingw-w64,都會有一個gdb.exe在安裝目錄的bin文件夾下,一定要把對應的路徑修正否則無法調試
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/develop/mingw64/bin/gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
2. tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
之后打開在當前工作區子目錄下的.c/cpp文件就可以添加斷點進行調試了
3. c_cpp_properties.json
如果找不到頭文件可以添加如下配置文件
其中,要將includePath選項更改為你mingw編譯器的安裝路徑下的lib/gcc/x86_64-w64-mingw32/8.1.0/include文件夾路徑
{
"configurations": [
{
"name": "Win32",
"includePath": [
"D:/develop/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
對於非標准庫中的頭文件,也可以通過列表追加的方式將路徑追加到includePath中去
比如:
"includePath": [
"C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"path1",
"path2",
...
],
4. 程序在終端下運行
依次打開:文件>首選項>設置>用戶設置>拓展>Run Code Configuration
找到 Run In Terminal 打上勾 這樣運行的程序就會運行在vscode的終端上
在工作區設置也有這個選項,但工作區設置只會對工作區生效
5. 程序運行時在終端無法輸入的問題
將輸入法切換到英文模式,中文模式下可能只能輸入個別數字然后卡死。
6. 常用插件
- C/C++
- C++ Intellisense
- Code Runner
- One Dark Pro
- Bracket Pair Colorizer