Reputation: 977
I am using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Where to look for it? I know how to add flags to force a particular standard with GNU extension.
Upvotes: 0
Views: 699
Reputation: 157484
You can use the predefined macro __cplusplus
:
$ echo __cplusplus | g++ -E -x c++ -c -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
199711L
Explanation of command line arguments:
-E
- only run preprocessor-x c++
- input file is a C++ source file (necessary for __cplusplus
to be defined)-c -
- read from stdinAlternatively, the -dM
option will dump all predefined macros:
$ g++ -dM -E -x c++ /dev/null | grep __cplusplus
#define __cplusplus 199711L
Upvotes: 1
Reputation: 58442
Like Jesper Juhl said, checking the docs is probably best.
If you want, though, you can also ask your compiler.
#include <iostream>
using namespace std;
int main(int, char**) {
cout << __cplusplus << endl;
return 0;
}
From the GCC docs on predefined macros, this will output one of the following:
199711L for the 1998 C++ standard, 201103L for the 2011 C++ standard, 201402L for the 2014 C++ standard, or an unspecified value strictly larger than 201402L for the experimental languages enabled by -std=c++1z and -std=gnu++1z.
Upvotes: 3
Reputation: 31478
Have you tried reading the documentation? man g++
is one place to start... But, to answer the question; that gcc version compiles as C++98 by default (actually, the GNU variant).
If you want to detect the C++version in use without reading documentation or without specifying -std=
, then you could just try compiling some code using only C++98, some using C++03 features, C++11 features and C++14 features and see which one(s) it accept.
But just reading the docs is easier.
Upvotes: 1