下载mingw编译器
配置环境变量
此电脑单击鼠标右键,打开属性
在窗口右边点击高级系统设置
在高级选项中点击环境变量
在系统变量中选中path并点击编辑
新建一个环境变量,路径为一个到bin的完整mingw编译器路径.(bin文件夹里有很多的exe文件,打开bin,直接复制路径到新建里面即可)
一路点确定回去,保存操作
检验是否配置成功
打开
命令提示符页面,输入gcc -v查看是否安装成功(不报错,显示版本号即成功)
下载Vscode
- 官网下载Vscode,一直点击下一步,直到安装在电脑上。打开Vscode.
- 点击扩展选项,搜索下载安装两个插件:C/C++和中文翻译包
- 先在电脑中随便建一个空文件夹,我建的是在E盘下的文件名为C++的文件夹
- 打开vscode,左上角选择文件,打开文件夹,打开刚刚创建的C++文件夹;
- 在该文件夹下创建一个hello.cpp的文件
#include<iostream>
using namespace std;
int main()
{
cout<<"hello董文龙"<<endl;
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
- tasks.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/app/mingw/mingw/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
- launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "D:/app/mingw/mingw/mingw64/bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/app/mingw/mingw/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
- c_cpp_properties.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:/app/mingw/mingw/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/app/mingw/mingw/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "test",
"isDefault": true
},
"detail": "编译器: D:/app/mingw/mingw/mingw64/bin/g++.exe"
}
]
}
回到hello.cpp文件,按下F5,弹出页面,大功告成!!