skip to Main Content

I’ve used C++17 in VS Code. Now I want to use C++20 or C++23, but I can’t change from the C++17 version.

I’ve tried many ways, like adding "-std-c++2b" in Task.json or setting C++Standard to C++23, but my VS Code is still in C++17. Maybe I reinstalled VS Code and set it again?

2

Answers


  1. Chosen as BEST ANSWER

    I used__cplusplus to check version c++ , here is my complile when i use C/C++ and Code Runner extension :

    Ctrl + alt + N

    the result is c++17.

    I tried to run the compile with mingw64 from MSYS2 : Run C/C++ file

    the result is c++20. Another , i used C/C++ runner extension to run and the result still in c++17:

    C/C++ Runner :Run


  2. In the VSCode project browse the .vscode folder and in the tasks.json type something like this (adapt it to your needs regarding the version):

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}",
                    "-std=c++23"  // Add this line for C++23
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    Also try to configure the c_cpp_properties.json:

    {
        "configurations": [
            {
                "name": "Win32",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [
                    "_DEBUG",
                    "UNICODE",
                    "_UNICODE"
                ],
                "windowsSdkVersion": "10.0.18362.0",
                "compilerPath": "C:/MinGW/bin/g++.exe",
                "cStandard": "c17",
                "cppStandard": "c++23"  // Change this line for C++23
            }
        ],
        "version": 4
    }
    

    Finally rebuild your project. It should work for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search