setup c++ 20 in vscode

first, update your g++ compiler to above g++11

in tasks.json file(automatically created while you create the project)

c 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++-11",
            "args": [
                "-std=g++20",
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

in settings.json file(automatically created while you click on c/c++: edit configurations(json) [ctrl + shift + p to call, require the c/c++ extension first] )

you can change your compiler here

bash 复制代码
{

    "code-runner.executorMap": {
        "cpp": "cd $dir && g++-11 -std=c++20 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        },
    "files.associations": {
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "bit": "cpp",
        "*.tcc": "cpp",
        "cstdint": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "numeric": "cpp",
        "optional": "cpp",
        "random": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "cinttypes": "cpp",
        "typeinfo": "cpp"
    }
}

in c_cpp_properties.json

bash 复制代码
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "g20",
            "cppStandard": "g++20",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}
相关推荐
冲上云霄的Jayden5 小时前
在 WSL 中安装 Google Chrome 浏览器
chrome·wsl
剑神一笑7 小时前
Linux zip 与 unzip 命令详解:压缩算法原理与实战技巧
linux·前端·chrome
程序手艺人8 小时前
【日常开发】 VSCode Remote SSH 在 Ubuntu 18.04 (GLIBC 2.27) 上的解决方案
vscode·ubuntu·ssh
龙之叶8 小时前
Android 12:在 ActivityStarter 层拦截分享、搜索与 HTTP 外链
android·chrome·http
培风图楠9 小时前
vscode初始配置环境后无法编译
ide·vscode·编辑器
君鼎10 小时前
内存池完整实现——C++20版
c++20·内存池
嵌入式小站10 小时前
STM32 临界区是什么:为什么有时候要用 __disable_irq() 保护变量
chrome·stm32·嵌入式硬件
bestlanzi12 小时前
使用vscode 搭建Java 开发环境
ide·vscode·编辑器
xiaobobo33301 天前
vscode+clangd打开头文件发现某些标识符不识别为“白色”语言模型识别为C++
vscode·识别头文件错误·标识符为白色·语言模型识别错误
basketball6161 天前
Linux sed 和 awk 命令使用方法
linux·运维·chrome