1.1.下载minGW
1.官网下载地址(下载非常慢不推荐):http://gcc.gnu.org/install/
官网镜像站:NJU Mirror
2.sourceforge下载网址(有时候进不去。推荐离线下载,一键直达下载):MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net
sourceforge镜像站:Download geoserver-2.21.1-bin.zip (GeoServer)
大部分网盘都有离线下载功能,如百度网盘(离线下载网址:https://sourceforge.net/projects/mingw-w64/files/latest/download)
3.如果进不去而又不想离线下载怎么办?有一个骚操作就是用手机下载然后Q/W传到电脑上(本人所用方法,手机并未出现进不去网站的情况)
大佬推荐的是下载x86_64-posix-sjlj版本(本人不知区别)
下载后进行安装,记住安装的路径(后面还会用)
1.2.在设置中新增变量Path
1.在设置中直接搜索高级系统设置
2.点击右下环境变量
3.进入后在系统变量内找到Path
4.双击进入后选择新建
5.找到自己GCC安装的路径然后输进去(本人的是蓝色的这个路径)
记得路径要一直到bin(例:E:\GCC\mingw64\bin)
1.3.在终端中确定GCC已经安装成功
1.按住键盘上win和R然后在指令框内输入cmd打开终端
2.在终端中输入gcc -v(c与-之间有空格)出现版本号即安装成功(图中倒数第二行)
2.1.VScode下载
1.官网链接:https://code.visualstudio.com/Download(个人下载很快且软件本身并不大,所以推荐。点击红色箭头所指即可下载,不用管下面的特殊版本)
如果嫌慢也可以去腾讯软件中心
2.下载完成后打开进行安装,没啥好说的,注意自己选一个自己喜欢的安装路径(后面还要用)(注意不要用中文给路径上的文件夹命名)
3.记得勾选环境
2.2.下载插件
1.点击右侧扩展图标
2.搜索C/C++和C/C++Extension Pack以及Code Runner并下载安装(如有中文需要搜索Chinese在下载完成后右下角会有询问是否更换语言的选项)
安装完成后重启VScode(还有很多的好用扩展可以自行查看)
2.3试运行:
2.3.1.创建文件夹并创建第一个c程序文件
1.在GCC所在的的同一磁盘内创建一个文件夹随意起名(不可以有中文)
2.在VScode中打开刚刚创建的文件夹(在VScode中点击右上文件后点打开文件夹,找到自己创建的文件)打开后创建一个文件,自己取名(后缀为.c ) 记得信任父级文件!!!(不要问笔者为什么有一个vscode文件,后面大家也要配置)
3.输入以下代码(可直接点击下面图片直接复制)
#include <stdio.h>
int main()//主函数
{
/* 第一次运行 C 程序 */
printf("Hello, World! \n");//库函数:打印数据
return 0;
}
2.3.2调试选择文件关注是否运行成功
1.点击图示图标
2.点击扩展
运行成功后会自动在同一文件夹中创建后缀为.exe的文件
3.win+R后输入cmd打开终端,直接将刚刚创建的.exe文件拖入其中,然后回车,显示hello world即成功
2.4.配置调试功能
重点来了,最关键的一点
1.在刚才那个文件夹中创建一个新的子文件夹命名.vscode(必须是这个名字)
2.然后在这个子文件夹下创建四个文件(点击下面图片可复制)
c_cpp_properties.json
launch.json
settings.json
tasks.json
3.复制四个文件夹内容
首先是c_cpp_properties.json
{
"configurations": [
{
"name": "Win64",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/MinGW/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
compilerPath后面的路径要改为自己的GCC文件中bin的g++所在,保持格式一致(直接复制过来的可能是右下划线自己改一下就好
然后是launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"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
}
]
}
]
}
此处改miDebuggerPath
然后是settnigs.json(不用改)
{
"files.associations": {
"*.py": "python",
"iostream": "cpp",
"*.tcc": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"ostream": "cpp",
"new": "cpp",
"typeinfo": "cpp",
"deque": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"fstream": "cpp",
"sstream": "cpp",
"map": "c",
"stdio.h": "c",
"algorithm": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"ios": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"random": "cpp",
"set": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"stdlib.h": "c",
"string.h": "c"
},
"editor.suggest.snippetsPreventQuickSuggestions": false,
"aiXcoder.showTrayIcon": true
}
最后是tasks.json(不用改)
{
"version": "2.0.0",
"tasks": [
{
"label": "g++",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"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
}
}
]
}
保存后就创建完成了
以后的C/C++代码就放在这个你所创建的文件中(我创建的文件夹名为code,则以后都会放在此)可多创建些子文件夹来分类
标签:文件,创建,一萌,json,文件夹,C++,准大,cpp,下载 From: https://blog.csdn.net/2401_86009609/article/details/140189898