前言
安装VSCode
安装mingw编译器
- 点击Files
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/dbac1009006b2d255fbcd44d4c65475d.png)
- 向下拉,点击下载(建议windows64位直接下载8.1.0版本的x86_64-win32-seh或者x86_64-posix-seh)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0c0ac1741bdca286ee84b0641357581f.png)
- 解压上一步下载的压缩包,例如:解压到D盘
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c47008604a9ae956380b07f069990916.png)
- 配置环境变量
- 此电脑右键–> 属性
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/07461f9c128d80f07becf84dff3a3064.png)
- 高级系统设置 --> 环境变量
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/43898c9044925a9b96e136902209e4fb.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bbe2be90819a237810881ef1f0329713.png)
- Paht中添加mingw64路径(需写到bin,如:D:\mingw64\bin)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/56d1944209080b2d14b3e31dbca67722.png)
- 验证配置是否成功
- 打开cmd命令窗口,输入g++ -v
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/210828b7301809f53fe2a42e97e87ed0.png)
VSCode配置C++环境
- 新建一个文件夹(如:C++),用vscode打开文件夹
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/73fe751447c2e6e015dbd9cee8b72ac5.png)
- 在C++文件夹下新建hello.cpp文件,写入如下代码
#include<iostream>
using namespace std;
int main(){
cout<<"Hello,VScode!"<<endl;
system("pause");
return 0;
}
- 按下CTRL+shift+P,调出面板,输入C/C++:Edit Configurations(UI)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/612157529e880a2ff16e231e60563a86.png)
- 填写编译路径(上面安装的mingw64路径,如:D:\mingw64\bin\g++.exe)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9aad5843f6094c6f37689b083d0a5c09.png)
- IntelliSense mode里选择gcc-x64
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2475a5c772a508b88942a62075102767.png)
- 此时会发现左边多了一个.vscode文件夹,并且里面有一个c_cpp_properties.json的文件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4201064c9561f9b315fd95aa1aab7b22.png)
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "D:\\mingw64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
- 按下CTRL+shift+P,调出面板,输入Tasks:Configure Default Build Task
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1e9c2b808ee6a7d63118e774e50d9f48.png)
- 再选择 C/C++:g++.exe build active file
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c3b347c8538f69d5b63438d0a7e4ee6a.png)
- 此时会在.vscode下出现一个tasks.json文件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/99e70d048db78d764586568244eb0a8f.png)
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: D:\\mingw64\\bin\\g++.exe"
}
]
}
- 运行代码验证配置
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/701d543e8131f842299bd3b2274d152a.png)