14

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 ?

Summit
  • 2,112
  • 2
  • 12
  • 36
  • Does this answer your question? [How to determine the version of the C++ standard used by the compiler?](https://stackoverflow.com/questions/2324658/how-to-determine-the-version-of-the-c-standard-used-by-the-compiler) – NutCracker Feb 04 '20 at 07:03
  • [You get the default 199711L](https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=vs-2019) unless you explicitly set the `/Zc:__cplusplus` compiler option – acraig5075 Feb 04 '20 at 07:03
  • Check [here](https://stackoverflow.com/a/51536462/5517378) also... Especially the comments – NutCracker Feb 04 '20 at 07:03

2 Answers2

30

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.

FireFragment
  • 596
  • 1
  • 4
  • 15
12

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.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621