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
}
相关推荐
曹申阳9 小时前
1. 使用VSCode开发uni-app环境搭建
ide·vscode·uni-app
每天更新11 小时前
VSCODE 使用GDB
ide·vscode·编辑器
傅科摆 _ py13 小时前
解决 Vscode 中运行键突然消失的问题
ide·vscode·编辑器
丨Sky丨夜吻13 小时前
vscode扩展
ide·vue.js·vscode
阑梦清川14 小时前
vscode远程连接云服务器的初次尝试
vscode
西瓜树枝15 小时前
Chrome 扩展开发从入门到实践:以 Cookie 跨页提取工具为例,拆解核心模块与交互逻辑
前端·javascript·chrome
Harriet嘉16 小时前
解决Chrome 140以上版本“此扩展程序不再受支持,因此已停用”问题 axure插件安装问题
前端·chrome
米花丶21 小时前
[实践] 如何使用Chrome工具排查内存泄露问题?
前端·chrome
Tajang21 小时前
推荐一个浏览器代理插件(Tajang Proxy),支持Chrome和Edge
前端·chrome·网络安全·渗透测试·靶场·edge
九河_1 天前
服务器在线安装插件失败/离线安装VSIX
vscode·extension·pylance