前言
????????关于c编辑器,早年读书的时候,我记得我们在学校首次接触的时候用的就是dev c++这个编辑器,说实话真好用,包括毕业后,不知道就业该去哪里的时候,我去面试过一个少儿编程的教育机构,也是靠这个编辑器给写了一个现场考题,很方便,不需要搭啥环境,直接可以在终端上运行,但也有缺陷
????????本文着重讲述vscode,至少目前对于c开发而言,这个编辑器确实是很好用,敲代码会有自动识别,熟悉后可以敲很快,大大缩短了不必要的麻烦
第一步
? ? ? ? 首先是下载,不论你电脑跑的是哪个系统(目前应该只有linux版本,windows版本和macos版本),直接进下面链接即可
Visual Studio Code - Code Editing. Redefinedhttps://code.visualstudio.com/第二步
????????安装完成后,进入vscode,现在的版本右下角是会自动跳出是否重启转换为中文的提示的,所以直接同意等待重启即可
? ? ? ? 重启后界面就转成中文了
第三步
? ? ? ? 按图下载些插件即可
第四步
? ? ? ? MinGW插件的下载,借鉴下面这个链接
MinGW-w64的安装及配置教程_Wendy的博客-CSDN博客_mingw64https://blog.csdn.net/didi_ya/article/details/111240502?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164548468816780269864216%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164548468816780269864216&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-111240502.first_rank_v2_pc_rank_v29&utm_term=mingw&spm=1018.2226.3001.4187实测是可以的,安装和环境配置后,作为编辑器就已经可以了
第五步
? ? ? ? 让c跑起来
?
?意思就是在终端输出
第六步
到现在为止,还剩最后一步,也是作为c编译器,vscode让我感觉最麻烦的地方,这里我还是强烈建议作为编译器还是用dev c++更加人性化
?如图所示,建立一个文件夹,文件夹下建立一个.vscode文件夹,在该文件夹下创建如下几个文件
由上到下命名1-3
依次复制如下代码过去
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
/*这一部分的代码来源于你在终端中查看gcc编译器而得到的地址
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
*/
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
/*这一部分的代码来源于你在终端中查看gcc编译器而得到的地址,和上面一致
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/MinGW/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
*/
]
}
}
],
"version": 4
}
?获取方法
在cmd.exe(终端)中输入如下命令: gcc -v -E -x c++ -
?这个就是了
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"preLaunchTask": "echo",
"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": "D:\\MinGW\\MinGW\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "echo",//这里和task.json的label相对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"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
}
}
第七步
? ? ? ? 现在在这个文件夹里用vscode打开hello.c
如下图所示
就完成了?
|