如何让VS Code识别'constexpr'?

时间:2018-05-21 20:28:55

标签: c++ macos visual-studio-code

当我使用Array ( [0] => Array ( [test-1] => testing <p>html tag</p> will be fixed [test-2] => ® valid and will be left intact [test-3] => © 2080 kept intact ) [1] => Array ( [test-4] => Array ( [test-5] => deeper fix on <p>html tag</p> test [test-6] => ® will be left intact [test-7] => © 2080 kept intact ) ) ) 时,VS Code会给我错误:“未知名称类型'constexpr'”。我在osx上做了一些关于constexpr的研究,发现我需要用constexpr进行编译。但我的问题不在于编译,只是让文本编辑器将-std=c++11识别为有效关键字。我需要constexpr才能使其有效吗?

如何让VS Code在#include上没有错误?

1 个答案:

答案 0 :(得分:1)

假设您已安装Microsoft C/C++扩展名,则问题很可能是它使用了错误的C ++标准。 constexprC++11(意味着2011年标准)中引入的,因此这是最低要求; C ++ 98和C ++ 03无法正常工作。

要告诉VSCode使用哪种标准,请转到命令面板(Ctrl + Shift + P)并键入“ C / C ++:编辑配置”,然后按Enter。向下滚动到“ C ++标准”,然后从下拉菜单中选择“ C ++ 11”(或更高版本):

C++ language selector dropdown

然后它将constexpr识别为关键字。

如果这不起作用,或者遇到其他问题,我建议您仔细阅读VSCode Getting Started with C++教程,因为这样可以使您从工作开始。

此外,检查“ C / C ++:日志诊断”命令的输出(在面板中)。这将报告有关VSCode认为它是为C ++配置的各种详细信息。

相关问题