msknapp
msknapp

Reputation: 1695

GCC using old version of C++

I'm learning C++ using the cplusplus website tutorials. I'm using the following software:

these are the latest versions available from yum. As I was following the tutorial, I noticed that a lot of what it was saying did not work for me. For example, I can't prefix strings with 'u', 'U', 'L', etc. Also, 'nullptr' is not recognized, it produces a compiler error. I looked around and noticed that these features were added in C++11. So of course I thought I must have an old version of C++.

According to the GCC documentation in section 2.2 of this page, "The default, if no C++ language dialect options are given, is -std=gnu++98".

So I figured I need to specify -std=gnu++0x. I tried putting that in my Code::Blocks compiler arguments but it changed nothing. Instead I checked the compiler flag "Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]". That also changed nothing.

Can somebody please tell me what I need to do to get Code::Blocks and GCC to use the current version of C++?

Upvotes: 0

Views: 1140

Answers (1)

user3160514
user3160514

Reputation:

The canonical flag to enable C++11 features is -std=c++11, but most of the C++11 features should work out of the box anyways, thanks to GCC extensions. You should set the flag anyways, because it's bad practice to rely on extensions when you can just adopt the new standard.

However, your version of GCC is a bit outdated. You should grab the last stable version from your package manager, or from https://www.gnu.org/software/gcc/index.html

Alternatively, you can try other compilers, a lot of them support C++11. Clang(++) is a popular choice.

Upvotes: 1

Related Questions