文章目录
1. vsCode配置C/C++环境
1. vsCode下载和安装
1. 下载Microsoft vsCode
2. 安装vsCode
![](https://i-blog.csdnimg.cn/blog_migrate/422914c9956be6f2ef2a54a8ea2444d1.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/23ee89dab8a16cfafe5ab7f0772764d2.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/511eb12cda5cc3d01ec30fd137f10044.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/15c13544c9cafbe57280f34aaf464fc9.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/72d26cb991aaada45c9d551657157e7a.png#pic_center)
![](https://i-blog.csdnimg.cn/blog_migrate/d3253c9907c44fe67ef78ddf4a3275c9.png#pic_center)
3. 下载中文插件
我这边已经下载过,刚卸载但是没有重启编译器,所以界面显示了中文
2. MinGW编译器下载和配置
1. 下载MinGW
- 在线安装——下载MinGW-W64-install.exe(速度慢)
- 下载压缩包——×86_64-posix-sjlj(速度快)
2. 下载后放到自己方便的目录,并复制文件里bin目录的路径(后面用得到)
3. 在系统环境变量配置path变量
- 可以win+Q直接搜索
![](https://i-blog.csdnimg.cn/blog_migrate/ef895f77d9d008d52460c5f12508796b.png#pic_center)
-
或者右键我的电脑——属性
-
点击高级系统设置(这边是win11的界面)
-
点击环境变量
-
找到Path——编辑
-
新建
-
把下载的MinGW里的bin目录路径粘贴在这里,我的电脑是F:\codeConfiguration\MinGW\bin
完成后是这样
4. 检查是否配置成功
-
打开cmd,
-
进入bin目录
-
输入gcc -v或gcc或g++
4.出现上述图片说明配置成功
3. vsCode配置c/c++
1. 下载c/c++插件
下载完成后重启vsCode
2. 配置
- 新建文件夹(用来放vsCode的项目)
![](https://i-blog.csdnimg.cn/blog_migrate/d82c713de9a9e3649452ce71d7a2eead.png#pic_center)
-
在vsCode文件夹下创建一个
.vscode
文件夹并创建3个文件分别是c_cpp_properties.json,launch.json,tasks.json
可以直接复制三个json文件,但是路径需要修改,备注的区域都需要,但其他位置都不要动
-
c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": ["${workspaceFolder}/**"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], "windowsSdkVersion": "10.0.17763.0", "compilerPath": "F:\\codeConfiguration\\minGW\\bin\\g++.exe", /*修改成自己bin目录下的g++.exe*/ "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "${default}" } ], "version": 4 }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
-
launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "F:\\codeConfiguration\\MinGW\\bin\\gdb.exe", /*修改成自己bin目录下的gdb.exe*/ "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "task g++" } ] }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "type": "shell", "label": "task g++", "command": "F:\\codeConfiguration\\MinGW\\bin\\g++.exe", /*修改成自己bin目录下的g++.exe*/ "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "F:\\codeConfiguration\\MinGW\\bin" /*修改成自己bin目录*/ }, "problemMatcher":[ "$gcc" ], "group": "build",
<span class="token punctuation">}</span> <span class="token punctuation">]</span>
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
3. 测试是否成功
- 创建一个文件夹放项目,项目名可以为helloWorld.cpp,然后按F5运行
#include <stdio.h> #include <windows.h> int main() { printf("Hello World\n"); system("pause"); return 0; }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-
成功!!!