Search code examples
c++standards

How to determine the version of the C++ standard used by the compiler?


How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known:

  • C++03
  • C++98

Solution

  • By my knowledge there is no overall way to do this. If you look at the headers of cross platform/multiple compiler supporting libraries you'll always find a lot of defines that use compiler specific constructs to determine such things:

    /*Define Microsoft Visual C++ .NET (32-bit) compiler */
    #if (defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER >= 1300)
         ...
    #endif
    
    /*Define Borland 5.0 C++ (16-bit) compiler */
    #if defined(__BORLANDC__) && !defined(__WIN32__)
         ...
    #endif
    

    You probably will have to do such defines yourself for all compilers you use.