参考
https://code.visualstudio.com/docs/cpp/config-mingw
https://zhuanlan.zhihu.com/p/77645306 主要
官网给出的配置过程稍微复杂一些
以下内容参考 知乎 唐铭 https://zhuanlan.zhihu.com/p/77645306
1.安装vscode
官网下载安装即可
2.安装mingw64
建议安装离线版
https://sourceforge.net/projects/mingw-w64/
安装好后添加环境变量
检测
3.安装插件
安装必要的插件,打开vscode,点击左面竖排第五个按钮,搜索并安装
- C/C++
- Code Runner
4.配置文件
新建文件夹(工作区)project
新建文件夹.vscode
新建文件launch.json,tasks.json
##launch.json 注意修改mingw路径
{
"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:/mingw64/mingw64/bin/gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
##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
}
}
5.具体调试