简体   繁体   中英

How to check c++ version in microsoft visual studio 2017

I am trying to check the version of c++ i have with the following code.

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

the output is C++98 version , but i am definitely able to use c++11 features so i think i am not getting the correct version from the code.

How can i check which version of c++ i am using ?

From https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/

You need to compile with the /Zc:__cplusplus switch to see the updated value of the __cplusplus macro.

Note that this was added in MSVC 2017 (version 15.7 Preview 3), it's not available in older versions.

Easier way to check it than writing a program is under Project (right-click your project name in solution explorer) > Properties > C/C++ > Language > C++ Language Standard

And you can also change it there.

I know it thanks to this answer .

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