问题
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