学习编程,一款界面友好,debug调试是必须的,不然没有学下去的动力,一下是个人配置经验
1:下载mingw64,具体下载过程百度可以解决
下载好后,配置环境变量
2:官网下载vscode
3:打开vscode,
在2中搜索c/c++插件,会发现有很多个,选择下载次数最多的那个就是了,点击install
3:新建一个文件夹,在里面新建一个以.c为后缀的c文件,代码随意,例如代码
#include<stdio.h>
int main()
{
printf("世界,你好");
return 0;
}
写完后,
点击箭头所指,按顺序会弹出选项,选择C++(GDB/LLDB),会生成一个launch.json文件,文件改为如下
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",//注意,这个不同路径可能不同,你们的不用改这
"setupCommands": [
{
"description": "Enable prety-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
然后返回c文件,按f5运行,会弹出找不到任务英文界面,点击第一个配置任务,然后自动生成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": "gcc.exe build active file",
"command": "C:\\Program Files\\mingw64\\bin\\g++.exe",路径不同,不用改
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw64\\bin"//路径不同,不用改
}
}
]
}
改完后,按ctrl+s保存,返回c文件,按f5运行,成功!