21

Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??

Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?

Joy
  • 1,707
  • 7
  • 29
  • 44

3 Answers3

25

That can be a tricky question. C++11 refers to a version of the standard, not to a version of the compiler. Different compilers, and different versions of any given compiler, will typically implement a mix of versions of the standard, at least for recent versions. More or less, because any implementation of C++11 will be fairly new, and thus probably fairly buggy.

Most compilers have options to output the version; many will output it systematically in verbose mode. For g++, try g++ --version. Recent versions of g++ do have some support for C++11, but you have to activate it with -std=c++0x (rather than the usual -std=c++03 or -std=c++98). As the name (c++0x, rather than c++11) indicates, it is not truly C++11; it is an implementation of some (most?) of the major new features, in a preliminary version based on various working papers, and not the final standard.

(FWIW: I don't think any compiler fully implements all of C++11, but I'd love to be proven wrong.)

James Kanze
  • 150,581
  • 18
  • 184
  • 329
  • 2
    As of this writing, no compiler fully implements C++11. However, the latest trunks of [Clang](http://clang.llvm.org/cxx_status.html) and [GCC](http://gcc.gnu.org/projects/cxx0x.html) do implement very similar subsets thereof. So if you ignore inheriting constructors, alignment, and C++11 attributes, as well as many of the threading language changes, you should be fine. Well, between those two compilers. – Nicol Bolas Apr 05 '12 at 19:29
  • 2
    For anyone else stumbling through here, this answer is out of date. See https://stackoverflow.com/questions/44734397/which-c-standard-is-the-default-when-compiling-with-g – Burrito Jan 12 '18 at 06:29
14

You can find out your compiler version like this:

g++ --version

That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0x flag:

g++ -std=c++0x ....

Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See here for a table of supported features.

EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
6

If you're in linux, checking the version is easy.

> gcc --version

Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html

I've used a few C++11 features myself, namely initializer lists, and the nullptr constant. I'm using GCC 4.6 and it's working fine.

edit: And yes, as @jaunchopanza said, you'll need the -std=c++0x compiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]

Nathan S.
  • 94
  • 1
  • 2