Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 can't find std::variant

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

Installed VC++ modules

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.

like image 670
MikeS159 Avatar asked Feb 13 '19 11:02

MikeS159


People also ask

What version of C++ does Visual Studio 2017 use?

Visual Studio 2017 version 15.3/std:c++17 enables the set of C++17 features implemented by the compiler.

How do I select C++ version in Visual Studio?

To set this compiler option in the Visual Studio development environment. Open the project's Property Pages dialog box. For more information, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > Language property page.

How do I know my compiler version in Visual Studio 2017?

Just select the “Individual Components” tab at the top of the installer screen and scroll down to the “Compilers, build tools, and runtimes” section. The 14.11 toolset is included in the VS2017 version 15.5 update 4 installer.

What version of C++ does Visual Studio support?

Available under /std:c++17 and /std:c++latest (or /std:c++20 starting in Visual Studio 2019 version 16.11):


2 Answers

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 enter image description here

like image 107
Stack Danny Avatar answered Oct 16 '22 19:10

Stack Danny


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

Then click Apply and OK.

like image 10
Öö Tiib Avatar answered Oct 16 '22 18:10

Öö Tiib