目录
1.准备
(1).下载vscode Documentation for Visual Studio Code
(2).下载C语言环境:MinGw官网: MinGw 百度网盘:链接(Devc++自带MinGw文件,可以使用自带的文件)
2.添加MinGw环境
将下载好的MinGw直接解压粘贴到一个自己不常用的地方(主要是避免以后误删),也可以放到C盘
在Windows系统的搜索框中搜索环境变量
将MinGw的bin和include路径添加到path
打开cmd输入gcc
如果输出:gcc: fatal error: no input files
compilation terminated.
则代表配置正常,否则请重新配置环境变量
3.vscode
插件:C/C++(运行c++必要插件)、Chinese(中文插件)、Code Runner(代码一键运行)
现在我在D盘新建一个要存放代码的地方(可以是任何地方)
注意!!!这里新进一定要是英文的,所有路径都要是英文的,包括父级文件夹
在vscode打开刚刚新建的文件夹
创建launch.json,tasks.json和settings.json文件
选择GDB
launch.json
true和false可以自己改写
ctrl+s保存
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
tasks.json
ctrl+s保存
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
settings.json
{
"files.associations": {
"stdio.h": "c"
}
}
ctrl+s保存
大功告成,建一个c文件试试
#include<stdio.h>
int main(){
printf("hello world");
return 0;
}
写一个hello world程序检测一下
如果是要用外置终端的话,需要将launch.json 文件中的false改成ttrue
然后在文件开头写上#include<stdlib.h>
文件末尾写上system("pause);冻结终端屏幕
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("hello world\n");
system("pause");
return 0;
}
第一次发布,请多担待૮꒰ ˶• ༝ •˶꒱ა