How to check C++ Compiler Version?

Ever since its inception, C++ has constantly been updating itself and releasing newer versions (often referred to as “standards”) over the last 20+ years. With so many updates, we often feel the need to check which C++ version we are currently using (incase we need to update to use a newer feature).


Check C++ Standard Version

Ever since the release of C++11 (in 2011), there has been an update every 3 years (2014, 2017, 2020 and a 2023 planned release). There is also the legacy C++98, released in 1997/1998.

Now how do we find out which version we have? As promised, the solution is simple. Simply copy paste the code and execute this on your device to find out!

#include <iostream>
using namespace std;

int main() {
    if (__cplusplus == 202002L) std::cout << "C++20\n";
    else 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";
}

I get C++17 as the output, which means I have the 2017 version.


Microsoft C++ Compiler Problem

The above code uses __cplusplus macro available on most C++ Compilers. (Just an FYI, I have the GCC compiler). However, in MSVC (Microsoft Visual Studio C++), you need to enable a special setting first before you can use this.

You need to compile with the /Zc:__cplusplus switch to see the updated and correct value of the __cplusplus macro.

Alternatively, a simpler solution (without having to run any commands) is to go under Project (right-click project name in solution explorer) > Properties > C/C++ > Language > C++ Language Standard. You also get the added benefit of being able to change your version from there.


This marks the end of the How to check C++ Compiler Version? Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments sections below.