vscode配置c/c++编辑环境
一.下载vscode
直接去官网下载即可
下载地址Visual Studio Code - Code Editing. Redefined
二.下载mingw解释器
1.在线安装
官网地址:
MinGW-w64 - for 32 and 64 bit Windows - Browse /mingw-w64/mingw-w64-release at SourceForge.net
往下拉能找到这个进行在线安装,但是现在这个好像安装会失败,于是采用离线安装的方式
2.离线安装
(1)安装包资源:链接: https://pan.baidu.com/s/1M7efz9Y5Ywnes0Rw1GO6XA?pwd=knkw 提取码: knkw 复制这段内容后打开百度网盘手机App,操作更方便哦
(2)解压存放到相应的路径
(3)配置环境变量
在path中配置环境变量
三、插件安装
1.c/c++
2.c/c++ Extension Pack
3.C++ Intellisense
4.Code Runner
5.Better C++ Syntax
6.Bracket Pair Colorizer
四、配置文件
1.新建一个项目在任意的位置
2.配置项目环境
配置编译器
不同于网上的那些配置,我这边直接介绍一种偷懒的办法
在项目根文件夹创建.vscode文件夹
在.vscode文件夹中创建launch.json和tasks.json
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "E:\\mingw64\\bin", //你的mingw的位置
"environment": [],
"externalConsole": false,
"internalConsoleOptions": "neverOpen",
"MIMode": "gdb",
"miDebuggerPath": "E:\\mingw64\\bin\\gdb.exe", //你的mingw的位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "compile"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "compile",
"command": "E:\\mingw64\\bin\\gcc.exe", //配置mingw路径.c++使用g++.exe
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "E:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: E:\\mingw64\\bin\\gcc.exe" //配置mingw路径.c++使用g++.exe
}
],
"presentation": {
"panel": "new"
}
}
最后的结构是这样的
五、环境优化
1.主题
这里个人推荐Brackets Dark
icon个人使用VSCode Great Icons
2.自动保存
选择onfocusChange(失去焦点后保存)
3.c语言模板设置
选择c.json
c.json
{
"Print to conaole":{
"prefix": "C", //在新建立的页面中输入C就会有智能提示,Tab就自动生成好了
"body": [
"/*",
" * @description $0",
" * @author Tansty",
" */",
"#include <stdio.h>",
"", //空行
"int main()", //main()函数
"{",
" $1", //最终光标会在这里等待输入
" return 0;", //结束
"}",
"",
],
"description": "A c file template." //用户输入后智能提示的内容(你可以用中文写“生成C模板”)
}
}