【发布时间】:2016-11-26 15:00:11
【问题描述】:
我正在编写一个程序,在编译代码时需要编译器版本信息。
为了简化问题,我的代码类似于
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout<<"The C++ compiler version is: "<<__STDC_VERSION__<<endl;
return 0;
}
我希望一旦它被编译并运行,它会输出:
C++编译器版本为:gcc 5.3.0
我尝试编译,报错:
$ 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;
^
如何在我的代码中正确获取编译器版本?
【问题讨论】:
-
没有跨不同编译器获取该信息的标准化方法。