title: Output Compiler Version in a C++ Program
body: <p>I am writing a program  which needs the information of compiler version as the code is compiled.</p>
  
  <p>To simplify the problem, my code is something like</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main(int argc, char** argv) {
  
      cout&lt;&lt;"The C++ compiler version is: "&lt;&lt;__STDC_VERSION__&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>
  
  <p>I would expected once it is compiled and it runs, it would output:</p>
  
  <p>The C++ compiler version is: gcc 5.3.0</p>
  
  <p>I tried to compile it, and got an error:</p>
  
  <pre><code>$ 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&lt;&lt;__STDC_VERSION__&lt;&lt;endl;
             ^
  </code></pre>
  
  <p>How to correctly get the compiler version in my code?</p>