VS Code配置C语言
1、安装VS Code
官网下载 https://code.visualstudio.com/ 之后一路安装就好了
2、安装MinGW
参考该博客 https://blog.csdn.net/he_yang_/article/details/103839052
安装完成后配置环境变量(具体的值参考自己的安装路径)
3、VS Code安装插件
4、配置插件
然后创建文件夹VC Code(随便起名),在资源管理器中选择文件夹,并在其中创建Test.c
然后尝试运行,会弹出窗口,按下图中选择,会创建一个名为.vscode文件夹,里面有个launch.json的文件
将launch.json的内容替换如下
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"preLaunchTask": "Compile",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"&",
"echo.",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole":true
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "Compile",//这里和task.json的label相对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
再在该文件夹中创建一个task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile", //与上面的内容对应
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe",
"-fexec-charset=GBK"//解决中文乱码
]
}
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
}
5、测试运行
再按下F5,就可以运行了
以后要是想用其他文件夹保存代码,记得把这个.vocode文件夹复制进去(省事的话,全部放在这个文件夹就好了)