1.为什么要用VSCode配置c++环境
对于为什么要配置VSCdoe中的c++环境,可能好多小伙伴都存在疑问?那我以一个过来人的视角告诉你,装逼!装逼!就是单纯的装逼!
2.安装MinGW Installer
1.安装MinGW Installer软件
首先我们要安装支持编译的软件,而MinGW Installer就是我们所需要的软件,这里我已经把地址放在下面了。安装地址 
安装步骤如下:   
2.安装依赖包
安装完MinGW 后,我们要安装c++ 环境所需的编译器,主要是以下三个:
mingw32-gcc.bin(c语言文件编译器) mingw32-gcc-g++.bin(c++语言编译器) mingw32-gdb.bin(调试编译后文件)   全部勾选完毕后,点击Installation 里的Apply Changes 
3.添加环境变量
因为博主的电脑已经更新到了Windows11 ,因此环境变量的打开可能会不太一样 首先点击此电脑   环境变量的路径即为安装MinGW 中bin 的地址   最后检查一下是否添加成功,Windows+R 进入命令管理器,输入cmd ,进入页面输入gcc -v  输入gcc -v -E -x c++ - 还可查看路径信息,每个人的路径信息大体都差不多,不同的就是安装位置跟版本号,后面配置c++环境时会用到 
4.安装VScode
安装完MinGW 后,我们就要开始安装VScode 了,下载地址我放在了下面VScode下载地址  安装教程如下:    
5.配置环境
1.安装中文插件

2.安装c/c++插件

3.配置c++环境
   三个文件的名字分别为 c_cpp_properties.json launch.json tasks.json 这三个文件中的代码均可直接复制我的,但是需要做些更改 其中c_cpp_properties.json 里的代码为
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"c:/mingw/include/**",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++/mingw32",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++/backward",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../include",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include-fixed"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
"c:/mingw/include/**",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++/mingw32",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include/c++/backward",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../include",
"c:/mingw/bin/../lib/gcc/mingw32/6.3.0/include-fixed"
]
}
}
],
"version": 4
}
更改如下:  launch.json 中的代码为
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
更改如下:  tasks.json 中的代码为
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
这个是最简单的,直接复制即可,无需更改
6.大功告成
配置过程已经全部完成,接下来就该我们进入测试模式了。   好耶,成功了!
|