ajo*_*eps 31 c++ visual-studio-code c++17 vscode-settings
我一直在 std::string_view 上出现错误曲线,但我能够构建得很好。有没有办法告诉智能感知或 C++ linter 使用 C++17?
我得到的具体错误是:
namespace "std" has no member "string_view"
Run Code Online (Sandbox Code Playgroud)
Mic*_*ade 31
现在这变得容易多了。cppstandard
在您的 vs 代码扩展设置中搜索,然后从下拉列表中选择您希望扩展使用的 C++ 版本。
为了确保您的调试器使用相同的版本,请确保您有这样的事情您tasks.json
,其中重要的线是--std
与行定义后的版本。
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果您tasks.json
直接复制上述内容,则需要out
在工作区根目录中命名一个文件夹。
Mar*_*377 19
在他们的 GitHub 问题跟踪器中有一个关于这个的帖子:std::string_view intellisense missing (CMake, VC++ 2017)。
在另一个问题中,据说扩展默认为 C++17,但尚不支持所有 C++17 特性:设置 C++ 标准。
c_cpp_properties.json 参考指南证实了这一点,其中列出了cppStandard
一个默认为 C++17的选项。(要编辑此文件,请按Ctrl+ Shift+P并输入C/CPP: Edit Configurations
)。
看来,他们只是还没有完全支持。
刚刚更新。我也遇到这个问题了。
我通过添加来解决它c_cpp_properties.json
Ctrl + Shift + P 然后选择C/C++:Edit Configurations (JSON)
cStandard
调整和的内容cppStandard
:
"cStandard": "gnu17",
"cppStandard": "gnu++17",
Run Code Online (Sandbox Code Playgroud)