ctrl+,
:打开用户设置ctrl+K
:显示快捷键ctrl+R
:切换工作区ctrl+Z
:自动换行ctrl+G
:转到行ctrl+P
:转到文件F5
:启动调试shift+F5
:停止调试F2
:全局重命名变量F8
:转到下一个错误或警告F12
:转到定义ALT+F12
:查看定义ctrl+K
:右侧打开Markdown预览
x86_64-win32-seh
下载在C盘中解压文件
进入mingw64下的bin文件夹,复制当前路径,Win + i唤起系统设置,输入高级系统设置并进入,点击环境变量,选择path,编辑,新建,粘贴路径,按下三个确定
打开VScode安装插件 Chinese 和 C/C++ ,等待安装完毕后重启VScode
切换C/C++插件至 1.8.4 版本
因最新版本不会自动生成launch.json文件,给后续优化带来不便,故退回旧版本
新建文件夹,修改为英文名称并进入,右键通过Code打开 若在安装时未勾选相关选项,可能没有这个选项,请自行在VScode内操作打开文件夹
注意新建的文件夹名必须是英文,否则编译会出错!
新建一个文件,英文命名且扩展名为 .c
编写相关代码如下:
#include
#include
int main()
{
printf("Hello World!\n");
printf("你好世界!\n");
system("pause"); // 防止运行后自动退出,需头文件stdlib.h
return 0;
}
VScode菜单栏,点击运行,启动调试,稍等程序运行,输出结果在下方终端,上方调试面板,点击最右边的 橙色方框 停止程序运行
请根据自己的需要进行优化,代码运行后 .vscode 文件夹会自动生成在你的源文件目录下.vscode 文件夹下的 task.json 和 launch.json 用来控制程序的运行和调试
将程序运行在外部控制台【推荐】
解决中文乱码问题【不推荐】
收纳生成的 exe 可执行文件【可选】
这样 .c 文件一多起来的时候,就不会出现 .exe 和 .c 相互穿插在目录中
他们放入的内容如下:
//c_cpp_properties.json
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "windows-gcc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
"C:/mingw64/include/**",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
]
},
"cStandard": "${default}",
"cppStandard": "${default}",
"compilerPath": "C:/mingw64/bin/gcc.exe"
}
],
"version": 4
}
这里注意mingw64的位置,请放入自己的mingw64的地址,我这里是直接放在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:\\Tools\\mingw64\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Administrator/OneDrive/桌面/Code",
"program": "c:/Users/Administrator/OneDrive/桌面/Code/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"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
}
}