引言
windows下配置C/C++环境,新手跟着步骤走即可
1.安装Vscode
官网下载(较慢)
国内镜像
2.安装Vscode C/C++扩展
3.安装MinGW-w64工具链
1.官网下载,或猛戳这里
2.下好后立即点击安装,一路默认即可。
3.选择完成打开运行框,运行以下命令安装 MinGW-w64 工具链
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
4.按 Enter 键继续,然后按Y确认
5.将 MinGW-w64 文件夹的路径添加到 Windows 环境变量中。
直接在windows搜索栏搜索“编辑系统环境变量”打开,按照以下步骤操作即可。
选择path点击编辑
如果全程默认则为:C:\msys64\ucrt64\bin,新建如下:
4.添加hello world源代码
1.创建项目Project--新建空文件夹hello--新建文件hello.cpp(C为C++子集)
2.用vscode打开,粘贴以下源代码:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
3.右上角运行
5.编译运行
选择“C/C++:g++.exe从系统上检测到的编译器列表中生成和调试活动文件”。
至此环境搭建结束。