1、安装MinGW/GCC编译器
2、配置环境变量 比如 E:MinGWin;
3、安装vscode
在cmd/powershell,输入code .
,可以打开vscode
4、安装vscode插件
打开vscode,按ctrl+p打开快速命令框,输入以下命令后等待
ext install cpptools
下载安装插件C/C++、C++ Intellisense
5、配置.vscode文件
第一,打开vscode,打开文件夹,新建一个文件夹,起名字,比如vscode,新建一个文件,起名字,比如test.cpp
#include <iostream> using namespace std; int main() { cout<<"Hello"; system("pause"); return 0; }
第二,按ctrl+shift+d,点击那个带着红点的齿轮,选择C++(GDB/LLDB),选择default configuration ,然后会在.vscode目录下,生成一个launch.json
的启动配置文件,修改如下:
{ "version": "0.2.0", "configurations": [ { "name": "(gdb)Launch", "type":"cppdbg", "request": "launch", "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe", // "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe", //miDebuggerPath是环境变量的路径,64位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","${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 } } }
6、调试.cpp
注:因为VS需要为每一个文件夹做单独配置,所以建议把.vscode
文件夹放到你常用的文件夹的顶层,这样就不用重复配置了