文章目录
Mingw(x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z)和Vscode(VSCodeUserSetup-x64-1.43.2)资源
链接:https://pan.baidu.com/s/1xBntoJSiaqA55yQH1jteeQ
提取码:aed2
一、下载Mingw
- 在https://sourceforge.net/projects/mingw-w64/files/中选择所需的版本,例如“x86_64-win32-seh”。
-
下载下来的是一个压缩包
x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z
,解压到你想安装的位置; -
把
\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\bin
添加到环境变量中(可以在cmd中输入gcc -v来确认环境变量是否添加成功);
二、VSCode-Code Runner
1.安装Code Runner插件
2.配置.vscde环境
其实这个图形化界面就是配置c_cpp_properties.json
,你配好后会发现这里出现文件自动创建出来了。
所以以下两种方法选择其一就行了。
(1)直接创建文件c_cpp_properties.json
- 先创建配置文件夹
.vscode
(PS:这个CPP文件夹就是你以后的工作空间,在这个工作空间下就能运行正常,在别的地方就失败。所以选一个固定的地方。)
- 创建
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
// 这里要改!改成你安装mingw的目录下的/bin/g++.exe
"compilerPath": "D:/mingw64/bin/g++.exe",
"cStandard": "c11", // c用c11
"cppStandard": "c++17", // c++用17
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
- 保存就好了
(2)图形化配置
-
View→Command Palette 或者 使用Ctrl+Shift+P快捷键打开VS Code Command Palette,搜索选择"C/C++: Edit Configurations (UI)"
-
更改编辑器路径,改成你安装mingw的目录下的/bin/g++.exe
-
选择IntelliSense模式为
gcc-x64
-
关闭,就会看见自动生成
3.运行
创建文件
在工作空间(我的是CPP文件夹)下创建一个hello.cpp
,要打上后缀。
PS:这个hello.cpp
不是在.vscode
文件夹下,而是和.vscode
文件夹是并行的,都是直接在CPP
文件夹下。
2. 内容
#include <iostream>
using namespace std;
int main()
{
cout << "hello!\n";
}
运行
-
快捷键Ctrl+Alt+n
-
插件按钮
三、VSCode-原生
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:/MyHacker/mingw64/bin/g++.exe", // 这里要改!改成你安装mingw的目录下的/bin/g++.exe
"cStandard": "c11", // c用c11
"cppStandard": "c++17", // c++用17
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"environment": [],
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
"preLaunchTask": "g++", // 调试会话开始前执行的任务,链接到tasks.json
"externalConsole": false, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb", // VSCode要使用的调试工具
// 整齐打印
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"linux": { // 下面是Linux平台下,需要配置的参数,这里暂时不用关心
},
"windows": { // 下面是Windows平台下,需要配置的参数
"miDebuggerPath": "E:/MyHacker/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
}
}
]
}
settings.json
{
// 解决终端中文乱码
"terminal.integrated.shellArgs.windows": ["-NoExit", "/c", "chcp 65001"],
"terminal.integrated.fontFamily": "Lucida Console",
// c++ 配置
"files.associations": {
"array": "cpp",
"*.tcc": "cpp",
"istream": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"iostream": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"typeinfo": "cpp",
"list": "cpp",
"unordered_set": "cpp"
},
"C_Cpp.errorSquiggles": "Enabled",
}
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"//一定要写上"{fileDirname}/",不然可以运行但是调试不了
], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group":{
"kind": "build",
"isDefault": true
}
}