保姆级手把手教你配置C++环境 (vscode下)
vscode环境下搭建C++环境
1.安装vscode
https://code.visualstudio.com/
选择合适版本即可
2.安装C++插件
在拓展里搜索C++,下载第一个即可。
3.安装MinGw
https://sourceforge.net/projects/mingw-w64/files/
慢的话请用魔法上网,具体自行搜索,或者问我。
下载的文件:进入网站后不要点击 “Download Lasted Version”,往下滑,找到最新版的 “x86_64-posix-seh”
安装MinGW:下载后是一个7z的压缩包,解压后移动到你想安装的位置即可。我的安装位置是:D:\cppsoft\mingw64
4.配置环境变量
在系统设置找到系统环境变量编辑
点击环境变量
自行添加(路径换成自己的)
点确定保存后开启cmd输入g++,如提示no input files 则说明Mingw64 安装成功,如果提示’g++’ 不是内部或外部命令,也不是可运行的程序或批处理文件则说明安装失败
5.配置vscode
文件->打开文件夹(自己建一个文件夹放代码)
选中main.cpp单击左侧三角形,会进入调试界面添加配置环境,选择C ++ windows 就会自动生成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:\\cppsoft\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++" //修改此项
}
]
}
此时再次点击三角形或者F5运行会提示没有task文件,vscode会自动生成task.json文件
编辑task.json文件,配置如下
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++", //修改此项
"command": "D:\\cppsoft\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
// "${file}",
"${cwd}//src//*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\cppsoft\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
再次运行,可以看到弹出对话框显示程序执行结果