c++ 版本
如何在代码中判断c++版本
使用 __cplusplus
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
cout << __GNUC__ << endl;
cout << __cplusplus << endl;
return 0;
}
结果如下:
$g++ test.cpp -o test && ./test
4
199711
$g++ test.cpp --std=c++14 -o test && ./test
4
201300
$g++ test.cpp --std=c++11 -o test && ./test
4
201103
$g++ test.cpp --std=c++17 -o test && ./test
g++: error: unrecognized command line option '--std=c++17'
$g++ --version
g++ (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.