我一直在 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 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
当没有异常时,C++ 异常会以何种方式减慢代码速In what ways do C++ exceptions slow down code when there are no exceptions thown?(当没有异常时,C++ 异常会以何种方式减慢代码速度?)
为什么要捕获异常作为对 const 的引用?Why catch an exception as reference-to-const?(为什么要捕获异常作为对 const 的引用?)
我应该何时以及如何使用异常处理?When and how should I use exception handling?(我应该何时以及如何使用异常处理?)
C++中异常对象的范围Scope of exception object in C++(C++中异常对象的范围)
从构造函数的初始化列表中捕获异常Catching exceptions from a constructor#39;s initializer list(从构造函数的初始化列表中捕获异常)
C++03 throw() 说明符 C++11 noexcept 之间的区别Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 说明符 C++11 noexcept 之间的区别)