How to check the C++ version is being used in Linux OS?

Viewed 14031

I have tried to print:

std::cout << __cplusplus;

And Getting 1 as output.

Also I have tried: g++ -version command. It produces the output:

g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 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.

How to determine the version of the C++ standard with the above output ??

Or Is there any other way ??

Somewhere I found like, Boost.Config has a plethora of macros that can be used to test for support for specific C++11 features.

3 Answers

I have tried to print:

std::cout << __cplusplus;

And Getting 1 as output

This is expected behavior for g++ 4.4.7, according to How to determine the version of the C++ standard used by the compiler?

gcc (apparently for nearly 10 years) had this value set to 1 ... until it was fixed when gcc 4.7.0 came out.

An alternative solution would be to keep your __cplusplus approach and upgrade to g++ 4.7.0 or higher.

Related