3

I am using Visual Studio 2015 for my programming tasks, and I was wondering what version of the C++ standard the compiler used.

Googling didn't result in anything.

I tested those conditions, but they don't work properly:

if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 201402L) std::cout << "C+14\n";
else if (__cplusplus == 19971L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";

The output is pre-standard. However, I don't think that my C++ standard is pre-standard because I can use auto when specifying a type, which can only be used in C++11.

So, is there any easy way to get the C++ standard in Visual Studio?

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
sclee1
  • 1,095
  • 1
  • 15
  • 36
  • 1
    I don't know an easy way to get a value programmatically, especially because it may support some but not all features of a particular standard, but you can see the features it supports from each standard iteration here: https://msdn.microsoft.com/en-gb/library/hh567368.aspx – Banex Oct 09 '16 at 19:21
  • Have you tried just printing out the value of the macro `__cplusplus`? – Some programmer dude Oct 09 '16 at 19:23
  • There are various macros to test implemented features here: http://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros. I don't know if VS implements those macros though. – zahir Oct 09 '16 at 19:23
  • 2
    I think VS does, but because it never fully conforms a C++ standard, it may have some in-between value :) – Rakete1111 Oct 09 '16 at 19:23
  • http://stackoverflow.com/a/27459246/560648 – Lightness Races in Orbit Oct 09 '16 at 19:36
  • @JoachimPileborg I didn't, but I will test it. – sclee1 Oct 09 '16 at 19:56

1 Answers1

2

You have a typo in else if (__cplusplus == 19971L) std::cout << "C++98\n";. It should be else if (__cplusplus == 199711L) std::cout << "C++98\n";.

This is still the version in VS2015, probably because it still doesn't support the standard to the full extent.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85