首页 > 编程语言 >VSCode搭建C和C++环境

VSCode搭建C和C++环境

时间:2022-10-19 18:48:08浏览次数:70  
标签:false VSCode C++ editor && fileNameWithoutExt true dir 搭建

@

目录

前言

说明下如何在VSCode下面搭建C/C++环境以及运行

下载

点击该链接,进行ming64安装包下载:ming64安装包
VSCode安装请自行百度,这里不在赘述。

安装

  1. 将下载完成后的安装包,解压放到C盘下面即可,如下图所示:

img

  1. 添加环境变量
    我的电脑上点击右键-->属性:进入环境变量配置C:\mingw64\bin; (要与mingw64安装位置相对应)

img

设置.vscode

在对应的工程目录下面新建.vscode文件,并且对应创建如下三个文件

img

c_cpp_properties.json

将下面内容直接复制到该文件下面即可

{
    "configurations": [
        {
            //win32 操作系统名字
            "name": "Win32",
            // 提供.h文件的搜索目录
            "includePath": [
                "C:/mingw64/include",
                "C:/mingw64/x86_64-w64-mingw32/include",
                //根据的安装路径更改
                "${workspaceRoot}/**"
            ],
            //编译时加入的宏定义
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "browse": {
                //阅读代码的时候 F12搜索函数的目录
                "path": [
                    "C:/mingw64/include",
                    "C:/mingw64/x86_64-w64-mingw32/include",
                    //根据的安装路径更改
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "compilerPath": "C:\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14"
        }
    ],
    "version": 4
}

launch.json

将下面内容直接复制到该文件下面即可

{
    // 悬停以查看现有属性的描述。
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x64",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "miDebuggerPath": "C:/mingw64/bin/gdb.exe",
            "MIMode": "gdb",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "internalConsoleOptions": "openOnFirstSessionStart",
            "externalConsole": false,
            "preLaunchTask": "gcc"
        }
    ]
}

settings.json

将下面内容直接复制到该文件下面即可

{
    "files.associations": {
        "stdarg.h": "c",
        "utils.h": "c",
        "string.h": "c",
        "typedef.h": "c",
        "stdlib.h": "c",
        "stdio.h": "c",
        "gd32f4xx_usart.h": "c",
        "gd32f4xx.h": "c",
        "limits": "c",
        "cmath": "cpp",
        "*.tcc": "cpp",
        "cstdlib": "cpp"
    },
    // 这里可以设置代码界面风格
    "C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, ColumnLimit: 150, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Linux, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false}",
    "code-runner.executorMap": {
        "c": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
    },
}

下载Code Runner 插件

打开VSCode, 进入应用商店,输入Code Runner 进行插件下载安装即可

img

运行代码

接下来在对应的工程下面 创建一个main文件,输入代码后,在main.c文件里点击右键选择RunCode 运行代码即可

img

VSCode我个人的配置项设置

用户区的

{
    "files.autoGuessEncoding": true,
    "files.trimTrailingWhitespace": false,
    "files.autoSave": "afterDelay",
    "files.encoding": "gb2312",
    "scm.alwaysShowActions": true,
    "debug.inlineValues": "on",
    "workbench.colorTheme": "Monokai",
    "extensions.closeExtensionDetailsOnViewChange": true,
    "extensions.ignoreRecommendations": true,
    "update.mode": "manual",
    "update.showReleaseNotes": false,
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "security.workspace.trust.untrustedFiles": "open",
    "cnblogsClientForVSCode.workspace": "e:\\other\\wei-ting",
    "git.path": "C:\\soft\\Git\\Git\\cmd\\git.exe",
    "git.ignoreMissingGitWarning": true,
    "git.enableSmartCommit": true,
    "git.ignoreLimitWarning": true,
    "git.ignoreLegacyWarning": true,
    "git.confirmSync": false,
    "git.autoStash": true,
    "git.alwaysShowStagedChangesResourceGroup": true,
    "editor.renderControlCharacters": true,
    "editor.renderWhitespace": "all",
    "editor.tabSize": 4,
    "editor.fontSize": 16,
    "editor.detectIndentation": false,
    "editor.autoClosingBrackets": "beforeWhitespace",
    "editor.dragAndDrop": false,
    "editor.wordWrapColumn": 180,
    "editor.largeFileOptimizations": false,
    "editor.formatOnSave": false,
    "diffEditor.ignoreTrimWhitespace": false,
    "typescript.format.enable": false,
    "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
    "typescript.format.placeOpenBraceOnNewLineForFunctions": false,
    "C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Linux, ColumnLimit: 150, AlignConsecutiveMacros: true,}",
    "C_Cpp.clang_format_sortIncludes": false,
    "C_Cpp.dimInactiveRegions": true,
    "code-runner.runInTerminal": true,
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.ignoreSelection": true,
    "code-runner.showRunIconInEditorTitleMenu": true,
    "code-runner.showRunCommandInEditorContextMenu": true,
    "code-runner.respectShebang": true,
    "code-runner.executorMap": {
        "c": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "python": "python"
    },
    "code-runner.executorMapByFileExtension": {
        ".vb": "cd $dir && vbc /nologo $fileName && $dir$fileNameWithoutExt",
        ".vbs": "cscript //Nologo",
        ".scala": "scala",
        ".jl": "julia",
        ".cr": "crystal",
        ".ml": "ocaml",
        ".exs": "elixir",
        ".hx": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        ".rkt": "racket",
        ".ahk": "autohotkey",
        ".au3": "autoit3",
        ".kt": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
        ".kts": "kotlinc -script",
        ".dart": "dart",
        ".pas": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        ".pp": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        ".d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        ".hs": "runhaskell",
        ".nim": "nim compile --verbosity:0 --hints:off --run",
        ".csproj": "dotnet run --project",
        ".fsproj": "dotnet run --project"
    },
    "code-runner.languageIdToFileExtensionMap": {
        "bat": ".bat",
        "powershell": ".ps1",
        "typescript": ".ts"
    },
    "[c]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "[cpp]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "workbench.editorAssociations": {
        "*.exe": "default"
    },
    "editor.suggestSelection": "first",
    "workbench.startupEditor": "none",
    "markdown-preview-enhanced.previewTheme": "vue.css",
    "explorer.excludeGitIgnore": true,
}

标签:false,VSCode,C++,editor,&&,fileNameWithoutExt,true,dir,搭建
From: https://www.cnblogs.com/Wei-Ting/p/16807341.html

相关文章

  • 实验3 数组、指针与现代C++标准库
    实验目的知道什么是类模板,会正确定义和使用简单的类模板能够描述数组的特性,会使用C++语法正确定义和访问内置数组,知道其局限性能够解释指针变量的特性,会使用C++语法正......
  • 实验3 数组,指针与现代c++标准库
    实验五:Info.hpp1#include<iostream>2#include<string>3#include<iomanip>4usingnamespacestd;5classInfo6{7private:8......
  • C++11 实现一个自动注册的工厂
    之前在项目代码里面看到同事写了个自动注册的工厂类,虽然当时我看不懂,但我大受震撼。今天又重新温习了一下这种写法,分享给大家,可见学好C++是多么的重要。实现动机工厂方法......
  • 记录一次阿里云ECS搭建代理服务器的过程
    [参考资料](Tinyproxy安装与配置(ip代理)-林先生(downdawn.com))1.一键安装脚本vimproxy.sh#!/bin/bash#配置文件CONFIG_FILE="/etc/tinyproxy/tinyproxy.con......
  • vscode 通过ssh远程连接多台服务器?
    目录需求操作需求想要把在linux终端操作的习惯改到本机上来。理由如下:linux下的vim对于编程调试不是很方便;编程与命令不能很好链接,经常要多开几个window或sessions;vi......
  • K8S二进制搭建问题云集
    一、故障描述Errorfromserver:Get"https://k8s-node01:10250/containerLogs/kube-system/calico-node-98cv6/calico-node":x509:certificatesignedbyunknownaut......
  • python+selenium环境搭建
    1、首先命令行进入到python安装目录的scripts目录下2、使用pip3installselenium,由于我是安装过的,所以会提示这个3、将谷歌浏览器的driver放到python安装目录下4、代码验证......
  • C++类模型漫谈(二)
    系统基于32位,MSVC编译器,VS开发工具1、通过对象对成员函数的调用,默认会给参数传进去一个this指针,该指针为对象的首地址,这个过程通常被编译器隐藏起来了。对象直接调用成员......
  • c++中正确编写包含类的头文件
         ......
  • 深入剖析Redis系列: Redis集群模式搭建与原理详解
    前言在Redis3.0之前,使用 哨兵(sentinel)机制来监控各个节点之间的状态。RedisCluster是Redis的 分布式解决方案,在3.0版本正式推出,有效地解决了Redis在 分布式 ......