Home > Backend Development > C++ > How Can I Fix C 17 `std::string_view` Errors in VSCode?

How Can I Fix C 17 `std::string_view` Errors in VSCode?

Mary-Kate Olsen
Release: 2024-11-29 00:06:12
Original
797 people have browsed it

How Can I Fix C  17 `std::string_view` Errors in VSCode?

Empowering C 17 Support in VSCode C Extension

Encountering persistent error squiggles on std::string_view despite successful builds often stems from a mismatch between the C standard used by VSCode's C extension and your code's requirements. To rectify this, navigate to "cppstandard" within your VSCode extension settings and select the desired C version.

For a seamless debugging experience, ensure that your tasks.json configuration aligns with your chosen C version. Here's an example tailored for C 17:

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-std=c++17",
        "-I",
        "${fileDirname}",
        "-g",
        "${fileDirname}/*.cpp",
        "-o",
        "${workspaceFolder}/out/${fileBasenameNoExtension}.o"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ],
  "version": "2.0.0"
}
Copy after login

Remember, if you're using the provided tasks.json directly, establish an "out" directory in your workspace root for successful compilation.

The above is the detailed content of How Can I Fix C 17 `std::string_view` Errors in VSCode?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template