简体   繁体   中英

Language supported in Visual studio for C++ __cplusplus is showing as C++98

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";

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM