How to check the current C++ version using Program

In this tutorial, we will learn how to check the current C++ Version using a program. For finding the current C++ version, we require knowledge of _cplusplus values of each version.

Here we will see the _cplusplus values of different C++ versions and write a program using those _cpluplus values with which we can check the current C++ Version. If you don’t know the values we will learn those values and then learn how to write a program using those _cplusplus values.

Program to Check current C++ version

Here is the list of the values of _cplusplus and their standards.

For C++ pre-C++98, the _cplusplus output value is 1.

For C++98, the _cplusplus output value is 199711L.

For C++11, the _cplusplus output value is 201103L.

For C++14, the _cplusplus output value is 201402L.

For C++17, the _cplusplus output value is 201703L.

Here we can use if-else if statements to write the code and the code is as follows. The program gets executed as a normal if-else if statement giving the required output.

C++ Program:

#include<iostream>
using namespace std;
int main () {
    if (__cplusplus == 199711L)
    cout << "The current version is C++98\n";
    else if (__cplusplus == 201103L)
    cout << "The current version is C++11\n";
    else if (__cplusplus == 201402L) 
    cout << "The current version is C++14\n";
    else if (__cplusplus == 201703L)
    cout << "The current version is C++17\n";
    else
    cout << "It is pre-standard C++\n";
}

Let us run this code for a C++ version and find out the output. Here I am testing the code in the compiler of C++14 version and lets check so let us run this program and check and find the output. Here is the link of the output attached running the above code.

Output:

The current version is C++14

How to check the current C++ version using Program

 

Leave a Reply

Your email address will not be published.