VS Code 搭建 C++ 环境

安装 vs code

官网地址

https://code.visualstudio.com/

下载完了之后,一直下一步,安装就 ok 了

安装 MinGW

下载压缩包

官网地址

https://www.mingw-w64.org/

点击左边的 downloads

选择 MingW-W64-builds

进入 GitHub https://github.com/niXman/mingw-builds-binaries/releases

选择下面这个进行下载

x86_64-13.2.0-release-win32-seh-ucrt-rt_v11-rev0.7z

配置环境变量

解压后得到 mingw64 文件夹,把这个文件夹放在合适的位置,比如D盘的根目录

将 mingw64 文件夹中 bin 目录的路径配置到环境变量中

在命令行窗口输入 gcc -v 查看版本号,检查是否配置成功

配置 vs code

安装 C/C++ 扩展

点击左边 extensions,搜索c/c++,然后安装

配置 c++ 环境

ctrl+shift+P 进入命令面板

输入如下,进入配置 ui 界面

c/c++:Edit Configurations(UI)

配置下面这些信息:

  • Compiler path
    E:\mingw64\bin\g++.exe
  • IntelliSense mode
    windows-gcc-x64
  • C standard
    c11
  • C++ standard
    c++17

配置文件

.vscode\c_cpp_properties.json

json 复制代码
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:\\mingw64\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

设置生成的 exe 文件路径

比如:根目录下的 out 文件夹

安装 code runner

点击左边 extensions,搜索 code runner,然后安装

配置文件

launch.json

json 复制代码
{
    // 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": [
        
        {
            "program": "${fileDirname}\\out\\${fileBasenameNoExtension}.exe", 
        }
        
    ]
}

.vscode\settings.json

json 复制代码
{
    "files.associations": {
        "iostream": "cpp",
        "cstdio": "cpp"
    },
    
    "code-runner.executorMap": {
        "cpp" :"cd $dir && g++ $fileName -o ${fileDirname}\\out\\$fileNameWithoutExt && ${fileDirname}\\out\\$fileNameWithoutExt"
    }
}

.vscode\tasks.json

json 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "E:\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\out\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "E:\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
相关推荐
sunny-ll37 分钟前
【C++】详解vector二维数组的全部操作(超细图例解析!!!)
c语言·开发语言·c++·算法·面试
嵌入式@秋刀鱼2 小时前
《第四章-筋骨淬炼》 C++修炼生涯笔记(基础篇)数组与函数
开发语言·数据结构·c++·笔记·算法·链表·visual studio code
嵌入式@秋刀鱼2 小时前
《第五章-心法进阶》 C++修炼生涯笔记(基础篇)指针与结构体⭐⭐⭐⭐⭐
c语言·开发语言·数据结构·c++·笔记·算法·visual studio code
whoarethenext2 小时前
使用 C/C++的OpenCV 裁剪 MP4 视频
c语言·c++·opencv
愚润求学2 小时前
【递归、搜索与回溯】FloodFill算法(二)
c++·算法·leetcode
泽02022 小时前
C++之list的自我实现
开发语言·数据结构·c++·算法·list
斗转星移32 小时前
c++默认类模板参数
开发语言·c++
福理原乡大王2 小时前
Linux信号详解
linux·运维·服务器·c++·ubuntu·信号处理
扫地的小何尚3 小时前
全新NVIDIA Llama Nemotron Nano视觉语言模型在OCR基准测试中准确率夺冠
c++·人工智能·语言模型·机器人·ocr·llama·gpu
埃伊蟹黄面3 小时前
C++ —— STL容器 —— string的模拟实现
c++