Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22155

Output Compiler Version in a C++ Program

$
0
0

I am writing a program which needs the information of compiler version as the code is compiled.

To simplify the problem, my code is something like

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    cout<<"The C++ compiler version is: "<<__STDC_VERSION__<<endl;

    return 0;
}

I would expected once it is compiled and it runs, it would output:

The C++ compiler version is: gcc 5.3.0

I tried to compile it, and got an error:

$ g++ main.cpp 
main.cpp: In function ‘int main(int, char**)’:
main.cpp:24:11: error: ‘__STDC_VERSION__’ was not declared in this scope
     cout<<__STDC_VERSION__<<endl;
           ^

How to correctly get the compiler version in my code?


Viewing all articles
Browse latest Browse all 22155

Trending Articles