Visual Studio 2017 can't find std::variant

不羁岁月 提交于 2020-02-03 08:26:33

问题


I am using Visual Studio 2017 - 15.9.7 for C++ development, and it looks like I have the necessary modules installed.

But the code below gives the error - "namespace "std" has no member "variant""

std::variant is supported in C++17 and looks like it was introduced to Visual Studio in 15.0

#include <iostream>
#include <variant>
int main()
{
    std::variant<int, double, std::string> value;
}

It looks like someone asked the same thing before, but the question appears to have been deleted.


回答1:


Project → Properties → C/C++ → Command Line /std:c++latest

Then click Apply and OK.




回答2:


You can also go Project > Properties > C/C++ > Language

and set C++ Language Standard to ISO C++17 Standard (/std:c++17)

make sure to be on All Configurations and All Platforms



来源:https://stackoverflow.com/questions/54668866/visual-studio-2017-cant-find-stdvariant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!