1.下载编辑器并安装
Visual Studio Code - Code Editing. Redefined
2.下载MinGW并解压
MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net
MinGW-W64 GCC-8.1.0下
选择 x86_64-win32-seh
3.
下载LLVM并安装
4. 解压MinGW,剪切到LLVM目录
5.配置VScode
安装插件:
Chinese语言包
C/C++
C/C++ Extension Pack
TabOut
6.在工作目录内创建.vscode文件夹
创建三个文件
c_cpp_properties.json
launch.json
tasks.json
c_cpp_properties.json文件配置
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:/Program Files/LLVM/bin/gcc.exe"
}
],
"version": 4
}
launch.json文件配置
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"preLaunchTask": "C/C++: gcc.exe 生成活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\LLVM\\bin\\gdb.exe",//编译器位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json文件配置
{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "C:\\Program Files\\LLVM\\bin\\gcc.exe",//编译器位置
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
//"-fexec-charset=GBK"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
},
],
"version": "2.0.0"
}
6.测试代码
C测试代码,F5运行
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello World!\n");
printf("C语言测试代码\n");
system("pause");
return 0;
}
C++测试代码,F5运行
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
cout << "C++语言测试代码\n";
system("pause");
return 0;
}
7.配置用户代码片段
VSCode --> 文件 --> 首选项 --> 配置用户代码片段 --> C
{
"Print to conaole":{
"prefix": ".c", //在新建立的页面中输入.c就会有智能提示,Tab就自动生成好了
"body": [
"#include <stdio.h>",
"#include <stdlib.h>",
"", //空行
"int main(void)", //main()函数
"{",
" $0", //最终光标会在这里等待输入
" system(\"pause\");", //等待用户动作
" return 0;", //结束
"}",
"",
],
"description": "A C file template." //用户输入后智能提示的内容
}
}
VSCode --> 文件 --> 首选项 --> 配置用户代码片段 --> C++
{
"Print to conaole":{
"prefix": ".cpp", //在新建立的页面中输入.cpp就会有智能提示,Tab就自动生成好了
"body": [
"#include <iostream>",
"", //空行
"using namespace std;", //标准命名空间
"",
"int main(void)", //main()函数
"{",
" $0", //最终光标会在这里等待输入
" system(\"pause\");", //标准C++的等待用户动作
" return 0;", //结束
"}",
"",
],
"description": "A cpp file template." //用户输入后智能提示的内容
}
}
文件-->首选项-->设置-->搜索终端-->调试:终端-->清除终端