文章目录
一、Mingw64
百度网盘链接:链接:https://pan.baidu.com/s/1_IzSUNhXGJrq9kq28MXd5w
提取码:60j7
不同版本的选择方法:
这里我选择的是:
二、mingw64设置环境变量
1.在环境环境变量中添加Mingw64中bin文件路径
!](https://img-blog.csdnimg.cn/51f80f717312465aba7a13ee69dc05f0.png)
2.测试环境变量是否正确添加
在windows PowerShell 中输入g++ -v 若显示mingw64的版本信息则说明环境变量成功配置
三、配置VScode
1.添加VScode C++插件
2.VScode C++插件设置
1.设置Code Runner插件(勾选在终端中运行和自动文件保存)
2.设置C/C++插件
在setting.json文件中按如下方式配置:
{
"python.jediEnabled": false,
"python.languageServer": "Default",
"python.defaultInterpreterPath": "D:\\Anaconda3\\python.exe",
"editor.fontSize": 22,
"security.workspace.trust.untrustedFiles": "open",
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true,
"C_Cpp.default.compilerPath": "D:\\ProgramFiles\\mingw64\\bin\\g++.exe",
"C_Cpp.default.cppStandard": "c++14",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.includePath": [
"D:\\ProgramFiles\\mingw64\\lib"
],
"C_Cpp.default.intelliSenseMode": "gcc-x64"
}
在工程文件夹下新建.vscode文件夹并新建launch.json和tasks.json文件
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:\\ProgramFiles\\mingw64\\bin\\gdb.exe", /*修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
tasks.json按如下设置:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\ProgramFiles\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\ProgramFiles\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
3.代码测试
代码如下(Code Runer 使用 ctr+alt+n 启动运行):
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout<<1<<endl;
cout<<1+1<<endl;
}
3.设置调试环境
按F5选择C++(GDB/LLDB) ->C/C++:g++.exe
进行相应调试
四、参考
https://www.bilibili.com/video/BV1TT4y1g7aF?spm_id_from=333.880.my_history.page.click