Macro __cplusplus Macro __cplusplus Macro __cplusplus

    #ifndef __cplusplus
      #error C++ is required
    #elif __cplusplus > 199711
      // C++11 (or newer) code goes here
    #else
      // old-school code goes here
    #endif
    C++98 #define __cplusplus199711
    C++11 #define __cplusplus201103
    C++14 #define __cplusplus201402
    C++17 #define __cplusplus201703
    C++20 #define __cplusplus202002

    If a compiler was released between C++ standards, values for __cplusplus might differ from the ones in the table above. However, you can always rely on the fact that the value of __cplusplus for a newer standard will be strictly larger than that of the previous standard.

    • used to use non-standard conforming values
    • compiler switch /Zc:__cplusplus (as of Visual Studio 2017 version 15.7) makes MSVC use the standard values

    use mostly standard conforming values for __cplusplus.