如何在 VSCode C++ 扩展中启用 C++17 支持

How to enable C++17 support in VSCode C++ Extension(如何在 VSCode C++ 扩展中启用 C++17 支持)

本文介绍了如何在 VSCode C++ 扩展中启用 C++17 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在 std::string_view 上出现错误曲线,但我能够构建得很好.有没有办法告诉智能感知或 C++ linter 使用 C++17?

I keep on getting error squiggles on std::string_view, but I am able to build just fine. Is there a way to tell intellisense or the C++ linter to use C++17?

我得到的具体错误是:

namespace "std" has no member "string_view"

推荐答案

现在这变得容易多了.在您的 vs code 扩展设置中搜索 cppstandard,然后从下拉列表中选择您希望扩展使用的 C++ 版本.

This has become much easier now. Search for cppstandard in your vs code extension settings and choose the version of C++ you want the extension to use from the drop down.

为了确保您的调试器使用相同的版本,请确保您的 tasks.json 具有类似的内容,其中重要的几行是 --std 和之后的行定义版本.

In order to make sure your debugger is using the same version, make sure you have something like this for your tasks.json, where the important lines are the --std and the line after that defines the version.

{
  "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"
}

请注意,如果您直接复制上述 tasks.json,则您的工作区根目录中需要有一个名为 out 的文件夹.

Note that if you're copying the above tasks.json directly, you'll need to have a folder named out in your workspace root.

这篇关于如何在 VSCode C++ 扩展中启用 C++17 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 VSCode C++ 扩展中启用 C++17 支持

基础教程推荐