Control C++ Standard Revision in visual studio 2019

Viewed 119

So I am using the visual studio 2019 for my C++ projects, I wanted to control the C++ version when compiling. I have changed it from "project > properties > C/C++ > Language > C++ Language standard > "

It was on Default (ISO C++14 Standard)

I used this to check the version:

#include<iostream>
using namespace std;

int main() {
    cout << __cplusplus << endl;
}

But the output is 199711

I changed the C++ language standard to ISO C++17 Standard (/std:c++17)

But still the output of __cplusplus is always 199711

Any idea?

1 Answers

According to Microsoft Docs:

The __cplusplus preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because lots of existing code appears to depend on the value of this macro matching "199711L", the compiler does not change the value of the macro unless you explicitly opt-in by using the /Zc:__cplusplus compiler option. The /Zc:__cplusplus option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if /Zc:__cplusplus- is specified, Visual Studio returns the value "199711L" for the __cplusplus preprocessor macro. The /permissive- option does not enable /Zc:__cplusplus.

So, you could add /Zc:__cplusplus or /Zc:__cplusplus- to the Additional options in Configuration Properties -> C/C++ -> Command Line.

Related