我有一个用C++ 20标准编译的程序。
g++ -std=c++2a test.cpp
#include <iostream>
#include <variant>
using namespace std;
int main(int argc, char *argv[])
{
variant<int, string> v{"hello"};
cout << get<string>(v) << endl;
}
我安装了C/C++扩展,我更改了设置以考虑到C++ 20标准as proposed before
C_Cpp › Default: Cpp Standard > C++ 20
在悬停variant
时,我得到以下错误
identifier "variant" is undefined C/C++(20)
如果我正确理解,variant
是std
的一部分,因为C++ 17,那么为什么扩展在告诉它使用C++ 20标准之后找不到它呢?
编辑1:
编译器版本是g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
。
编辑2:
我没有cpp_properties.json文件,我只是安装了扩展名,并在设置中更改了C++标准版本。
发布于 2021-04-21 17:51:39
正如评论中提到的,问题来自于cpp_properties.json
。
即使在更改设置之后,我也在项目中找到了多个隐藏的.vscode
文件夹,其中包含有错误标准的cpp_properties.json
。
我手动更改了cpp_properties.json
文件,这样就可以了。
https://stackoverflow.com/questions/67192391
复制相似问题