44

Yesterday I upgraded to the latest VS Community 2017 (the previous one was installed last year) and wanted to check the C++ standard. So I run the following code that checks it, and as it turns out, I have C++98:

#include<iostream>
using namespace std;
int main()
{
    cout << __cplusplus << endl;
    system("pause");
}

Which outputs

199711

Why don't I have the latest C++ standard?

screenshot of the code, output and vs version

Boann
  • 48,794
  • 16
  • 117
  • 146
eagleye
  • 582
  • 1
  • 8
  • 12

1 Answers1

47

The value of __cplusplus is temporarily intentionally non-conformant by default for current versions of Visual Studio in order to avoid breaking existing code. It does not mean your compiler does not support any C++11 (or newer) features.

Quoting from MSVC now correctly reports __cplusplus:

/Zc:__cplusplus

You need to compile with the /Zc:__cplusplus switch to see the updated value of the __cplusplus macro. We tried updating the macro by default and discovered that a lot of code doesn’t compile correctly when we change the value of __cplusplus. We’ll continue to require use of the /Zc:__cplusplus switch for all minor versions of MSVC in the 19.xx family.

  • 2
    success! I followed the instructions on setting /Zc:__cplusplus to enabled and I see I have c++14 (201402). This is the guide for doing this: https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=vs-2017 – eagleye Sep 23 '18 at 12:12
  • 7
    If the actual standard the compiler is enforcing is the focus of concern, rather than the value of that macro, you can right click on your Project in the Solution Explorer. and Select `Properties`. Then expand the `C/C++` menu on the left, and choose the `Language` submenu. There you can choose `++14`,`++17`, or `++latest`. – schulmaster Sep 23 '18 at 23:31
  • Even with C++ set to a particular C++ standard, one's compiler may not support every feature for that standard. Here's a [feature test](https://en.cppreference.com/w/cpp/feature_test) program that can help discern if one's compiler supports the desired core or library feature, which `__cplusplus` may be misleading if used as a check. – Eljay Jan 23 '21 at 13:50