Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what c++ norme i'm currently using? [duplicate]

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 ?

like image 288
Joy Avatar asked Apr 05 '12 09:04

Joy


People also ask

How do you check which C++ version I am using?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result.

What is the latest version of C++?

C++20 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++20 replaced the prior version of the C++ standard, called C++17. The standard was technically finalized by WG21 at the meeting in Prague in February 2020, approved on 4 September 2020, and published in December 2020.


3 Answers

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.)

like image 74
James Kanze Avatar answered Oct 03 '22 05:10

James Kanze


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.

like image 38
juanchopanza Avatar answered Oct 03 '22 03:10

juanchopanza


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]

like image 36
Nathan S. Avatar answered Oct 03 '22 03:10

Nathan S.