使用vsCode进行编写c语言,首先需要安装gcc编译器,可以自己去寻找资料或者gcc官网进行下载.
下载好后,将文件夹放入到自己指定的目录后,配置系统环境变量,将path指向编译器的bin目录
进入bin目录打开cmd,输入gcc -v,然后就会成功输出信息.
打开vsCode,下载C/C++插件,下载好后创建新的文件夹,用于存放vsCode代码文件,在其下面再创建一个.vsCode文件夹,用于存放编译配置信息,其下存放三个文件,分别是:
1.c_cpp_properties
{
"configurations": [
{
"name": "Win32",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:\\Program Files (x86)\\MinGW\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
2.launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\MinGW\\bin\\gdb.exe", /*修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
]
}
3.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": "task g++",
"command": "C:\\Program Files (x86)\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:\\vsCodeDemo\\cDemo",
"-std=c++17"
],
"options": {
"cwd": "C:\\Program Files (x86)\\MinGW\\bin"
},
"problemMatcher":[
"$gcc"
],
"group": "build",
}
]
}
完成上面步骤后,创建自己项目的文件夹,并创建一个xxx.c为后缀的文件,按F5进入调试运行,程序成功运行!很好,接下来让我们继续学习C吧.