Reputation: 301
I'm trying to run C++11 in my project. I add the compiler flag /std:c++11
to the compiler, but when I check the version and print it out, it shows as C++98. This is in Visual Studio 2019.
This is what I'm using to print the language, and it shows as C++98:
if (__cplusplus == 201703L) std::cout << "C++17\n";
else if (__cplusplus == 201402L) std::cout << "C++14\n";
else if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 199711L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";
std::cout << "C++ langauge supported = " << __cplusplus << "\n";
Upvotes: 5
Views: 803
Reputation: 10105
/Zc:__cplusplus
is required to turn on proper versioning for the __cplusplus
macro.
Note, however, that The compiler does not support standards switches for C++98, C++03, or C++11. So it will only work with /std:c++14
and later.
As was mentioned by Ted Lyngmo, there's also the _MSVC_LANG
marco (this does not require the above compiler flag):
_MSVC_LANG
Defined as an integer literal that specifies the C++ language standard targeted by the compiler. It's set only in code compiled as C++. The macro is the integer literal value 201402L by default, or when the/std:c++14
compiler option is specified. The macro is set to 201703L if the/std:c++17
compiler option is specified. It's set to a higher, unspecified value when the/std:c++latest
option is specified. Otherwise, the macro is undefined.
See this Visual C++ blog post for more background on this behavior and the new switch.
Upvotes: 8