問題描述
我一直在 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
,則您的工作區(qū)根目錄中需要有一個名為 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 支持的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!