VsCode c++环境配置(最新版)一. 前言二. 相应软件安装2. 安装VsCode下载 c/c++ 扩展 如图 安装之后重启一下vscode
三. vscode环境配置1. 创建工作区2. 配置文件在 此文件夹下建立一个文件夹 名为.vscode 文件夹 在 .vscode文件夹中 新建三个json文件 注意名字必须一模一样 c_cpp_properties.json launch.json tasks.json
把如下代码复制到对应json 文件中,修改对应内容,一般是 MinGW 路径 c_cpp_properties.json 在你本地需要修改的是 compilerPath 修改 成 你 MinGW下面的 bin / g++.exe {
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
//此处是编译器路径,以后可直接在此修改
"compilerPath": "D:/Environment/CodeBlocks/MinGW/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
} 修改 {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
"type": "cppdbg",//配置类型,只能为cppdbg
"request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
"args": [],//调试传递参数
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
"MIMode": "gdb",
"miDebuggerPath": "D:/Environment/CodeBlocks/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
} 修改command 和 options 中的 cwd {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file", //这里注意一下,见下文
"command": "D:\\Environment\\CodeBlocks\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Environment\\CodeBlocks\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
四. 测试在 .vscode 文件夹 同级目录 中建立 cpp 文件 敲一个c ++ 代码,然后F5 调试,把.vscode文件夹放在最上头,然后在和他同级 或者更低的目录下 执行cpp文件 #include<iostream>
using namespace std;
int main(void)
{
cout<<"Hello world";
cout<<endl;
// 最后 system pause 终端窗口不会执行完立即关闭
int pause;
cin>>pause;
return 0;
} 五. 其他插件推荐1. Code runner可以运行 c c++ Python PHP, Perl, Ruby, Go, Lua, Groovy, PowerShell, CMD, BASH, F#, C#, VBScript, TypeScript, 等所有语言 直接点击小三角 既可以运行
2. Codelf搜索GitHub, Bitbucket, GitLab来找到真实的使用变量名,为你提供一些高频使用的词汇,同时为你标明使用的语言、代码链接。 可以直接在网页上搜索要命令的词汇,当然,它不仅有网页版,也支持VS Code, Atom, Sublime, WebStorm等开发工具。 3. vscode-icons4. Bracket Pair Colorizer这款插件可以给() 、[] 、{} 这些常用括号显示不同颜色,当点击对应括号时能够用线段直接链接到一起,让层次结构一目了然。除此之外,它还支持用户自定义符号。 5. Markdown All in One对于开发过程中涉及到的API接口文档、README,可以直接使用VS Code。
|