Home >Backend Development >C++ >How Do I Enable C 17 Support in Visual Studio Code?

How Do I Enable C 17 Support in Visual Studio Code?

Barbara Streisand
Barbara StreisandOriginal
2024-11-29 05:48:08759browse

How Do I Enable C  17 Support in Visual Studio Code?

Enabling C 17 Support in Visual Studio Code C Extension

Problem:
In Visual Studio Code (VSCode), developers may encounter errors when using C 17 features like std::string_view. Despite successfully building the code, the editor throws error squiggles, suggesting a lack of C 17 support.

Solution:

To resolve this issue and enable C 17 support:

In VSCode:

  1. Search for "cppstandard" in the extension settings.
  2. In the dropdown menu, select the desired C version (e.g., C 17).

For the Debugger:

  1. In the "tasks.json" file, ensure the following lines are present:

    • "-std=c 17": Specifies the C 17 standard.
    • "defines": ["_GLIBCXX_USE_CXX11_ABI=0"]: Prevents the debugger from using the outdated C 11 ABI.
{
  ...
  "tasks": [
    {
      ...
      "args": [
        "-std=c++17",
        "-I",
        "${fileDirname}",
        "-g",
        "${fileDirname}/*.cpp",
        "-o",
        "${workspaceFolder}/out/${fileBasenameNoExtension}.o"
      ],
      ...
      "defines": ["_GLIBCXX_USE_CXX11_ABI=0"]
      ...
    }
  ]
  ...
}

Note: Ensure that a folder named "out" exists in your workspace root.

By following these steps, you can effectively enable C 17 support in VSCode and ensure that both the editor and debugger use the correct C version, eliminating error squiggles and allowing for seamless development with C 17 features.

The above is the detailed content of How Do I Enable C 17 Support in Visual Studio Code?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn