文章目录
- 📚Step1:下载安装VSCode
- 📚Step2:下载安装g++
- 📚Step3:编辑环境变量
- 📚Step4:安装vscode插件
- 📚Step5:建好文件夹⭐️
- 📚Step6:开始调试
📚Step1:下载安装VSCode
-
安装官网
-
双击exe开始安装,基本按提示往下。注意:安装路径不要含有中文。
-
安装结束
📚Step2:下载安装g++
- 下载链接
- 下载完成后双击安装,安装路径同样不包含中文。
📚Step3:编辑环境变量
-
打开安装路径,找到并打开
MinGW -> bin
,双击地址栏空白处,复制路径。
-
全局搜索环境变量,并打开编辑面板。
-
找到
Path
,点击编辑。
-
新建环境变量,输入刚刚复制的路径。记得 连续点三个确定。
-
查看g++版本确认是否配置成功:
win+R+cmd
📚Step4:安装vscode插件
-
中文包插件
-
插件①
-
插件②
📚Step5:建好文件夹⭐️
-
在你希望的位置建一个文件夹,不要用中文命名
-
进入VSCode,左上角
文件 -> 打开文件夹
,打开文件夹。 -
新建名为
.vscode
的文件夹(名字固定)
-
依次在
.vscode
文件夹内创建以下几个文件,并粘贴上对应内容:c_cpp_properties.json
,关注compilerPath
部分路径和本地MinGW下载路径对应!{ "configurations": [ { "name": "Win64", "includePath": ["${workspaceFolder}/**"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "D:/MinGW/bin/g++.exe", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 }
launch.json
,同理,关注miDebuggerPath
路径。{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe", "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
settings.json
{ "files.associations": { "*.py": "python", "iostream": "cpp", "*.tcc": "cpp", "string": "cpp", "unordered_map": "cpp", "vector": "cpp", "ostream": "cpp", "new": "cpp", "typeinfo": "cpp", "deque": "cpp", "initializer_list": "cpp", "iosfwd": "cpp", "fstream": "cpp", "sstream": "cpp", "map": "c", "stdio.h": "c", "algorithm": "cpp", "atomic": "cpp", "bit": "cpp", "cctype": "cpp", "clocale": "cpp", "cmath": "cpp", "compare": "cpp", "concepts": "cpp", "cstddef": "cpp", "cstdint": "cpp", "cstdio": "cpp", "cstdlib": "cpp", "cstring": "cpp", "ctime": "cpp", "cwchar": "cpp", "exception": "cpp", "ios": "cpp", "istream": "cpp", "iterator": "cpp", "limits": "cpp", "memory": "cpp", "random": "cpp", "set": "cpp", "stack": "cpp", "stdexcept": "cpp", "streambuf": "cpp", "system_error": "cpp", "tuple": "cpp", "type_traits": "cpp", "utility": "cpp", "xfacet": "cpp", "xiosbase": "cpp", "xlocale": "cpp", "xlocinfo": "cpp", "xlocnum": "cpp", "xmemory": "cpp", "xstddef": "cpp", "xstring": "cpp", "xtr1common": "cpp", "xtree": "cpp", "xutility": "cpp", "stdlib.h": "c", "string.h": "c" }, "editor.suggest.snippetsPreventQuickSuggestions": false, "aiXcoder.showTrayIcon": true }
tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "g++", "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/C++代码文件必须放在有
.vscode
文件夹的文件夹里,否则调试会报错!
📚Step6:开始调试
-
新建一个
.c
或.cpp
文件。
-
直接点击开始图标运行,调试成功。
- 参考博客
- VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统—保姆级教程
- vscode配置C/C++环境(超详细保姆级教学)