文章目录
一、下载mingw并配置gcc
下载地址:https://sourceforge.net/projects/mingw-w64/files/
下载的文件:进入网站后不要点击 “Download Lasted Version”,往下滑,找到最新版的 “x86_64-posix-seh”。
下载完成之后解压。
将bin目录添加到环境变量path
。


打开cmd运行 g++
出现:
g++: fatal error: no input files
则安装成功。
否则安装失败。
二、vscode的配置
1.安装vscode c/c++
插件

你可以阅读Get Start with C++ Mingw-w64。
这是关于这个插件如何配置的英文文档。
或者你可以继续看接下来的内容,为简略中文版。
2. 创建一个文件夹project
作为你的c++工作区域
创建一个文件夹project
作为你的c++工作区域。
在vscode中打开这个文件夹,并新建一个test.cpp
文件。
在test.cpp
中任意输入一段代码。
#include <iostream>
using namespace std;
int main()
{
cout << "hello" << endl;
system("pause");
return 0;
}
3. 修改launch.json
文件和task.json
文件
点击顶部菜单栏中 终端
- 配置默认生成任务
选择 g++.ext buid and debug active file
,如图:
此时会弹出task.json
,不必修改,回到test.cpp
页面。
点击F5
,此时会再让你选择一次,请同样选择 g++.ext buid and debug active file
。
此时会弹出 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": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //修改此项,让其弹出终端
"MIMode": "gdb",
"miDebuggerPath": "D:\\Mingw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
修改 externalConsole
参数为 true
。含义为让其弹出终端。
注:launch.json
中的 preLaunchTask
参数必须与 task.json
中的label
参数相同!
如果不知道其含义,保持默认值不修改即可!
此时再次回到代码页面,摁下F5后成功运行!