vscode官网下载合适版本
安装vscode插件
安装 MinGW
配置环境变量
把安装目录D:\mingw64 配置在用户的环境变量path里即可
选择用户环境变量path
点确定保存后开启cmd输入g++,如提示no input files 则说明Mingw64 安装成功,如果提示'g++' 不是内部或外部命令,也不是可运行的程序或批处理文件则说明安装失败
配置 vscode
我的项目结构是这样的,incude文件夹下为.h文件 src文件夹下为.cpp文件
点击运行与调试
点击运行与调试---》G++(Windows)
打开launch.json
配置launch.json
{"version": "0.2.0",//版本"configurations": [//配置{"name": "g++.exe build and debug active file",//名字"type": "cppdbg","request": "launch",//要求"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//"args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true, //修改此项,让其弹出终端"MIMode": "gdb","miDebuggerPath": "D:\\SoftWare\\mingw64\\bin\\gdb.exe","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "task g++" //修改此项}]
}
点击运行与调试---》
选择Others
配置
{"version": "2.0.0","tasks": [{"type": "shell","label": "task g++", //修改此项"command": "D:\\SoftWare\\mingw64\\bin\\g++.exe","args": ["-g",// "${file}","${cwd}//src//*.cpp","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"],"options": {"cwd": "D:\\SoftWare\\mingw64\\bin"},"problemMatcher": ["$gcc"],"group": "build"}]
}