So I'm following the tutorials on this page: http://www.cplusplus.com/doc/tutorial/control/ But I'm having trouble doing a range/based for loop. I found this page: GNU GCC compiler updatingThe answer there says I should open "Project" and "Properties". But when I try that, the "Properties" option is grayed out with no explanation: http://imageshack.com/a/img571/4371/xd1x.png So.. how can I activate range/based for loops?
9 Answers
Pass -std=c++11
flag to the compiler. Certainly GCC should be fresh enough (>=4.7) to support all these modern standards. For CodeBlocks 13.12: Settings -> Compiler -> Tab "Compiler Flags" -> Option "Have g++ follow the C++11 ISO C++ [-std=c++11]"

- 16,836
- 3
- 30
- 56
-
I'm going through a beginner's tutorial, which means I'm a complete noob here. What does it mean to pass a flag to the compiler? – Sindre Apr 04 '14 at 09:54
-
Well, specify that string among other compiler options in the command line, like this: `g++ -std=c++11 -o test_executable test_source.cpp` – user3159253 Apr 04 '14 at 10:01
-
1
-
How do you compile your code? In an IDE? Try to locate a place in the IDE menu (Settings?) where compiler invocation is configured. – user3159253 Apr 04 '14 at 10:42
-
Indeed, I use Code Blocks! Sorry, forgot to mention that. I posted a picture in the first post showing I can't access the properties for some reason – Sindre Apr 04 '14 at 10:44
-
GCC 4.7 supports some of C++11 but by no means all of it. Regex support is only available from 4.9 and many other features were introduced in 4.8. – Lightness Races in Orbit Apr 04 '14 at 11:22
-
The above given solution of using -std=c++11
didn't work for me.
This is the target and version detail of my compiler.
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Target: x86_64-linux-gnu
When I tried, this is what happened.
$ g++ -std=c++11 program.cpp
cc1plus: error: unrecognized command line option ‘-std=c++11’
This solved the problem for me.
$ g++ -std=c++0x program.cpp

- 3,143
- 1
- 32
- 42
In Dev-Cpp 5.11 Simply you can click on Tools>Compiler Options>Settings>Code Generation>(and in last option)Language standard(-std) select from dropdown (ISO C++ 11).

- 3
- 3

- 91
- 1
- 2
If you faced this error in Code::Blocks, this might help you -
Click on Settings -> Compiler -> Compiler Settings -> Compiler Flags
Under the "General" section, check [✓] the box beside : Have g++ follow the C++11 ISO C++ language standard [-std=c++11]

- 33,915
- 22
- 119
- 174

- 49
- 3
Both of these:
g++ -std=c++11 -o test_executable test_source.cpp
g++ -std=c++0x -o program program.cpp
worked for me.
Only thing to do after compiling is to execute the test_executable
(in the first case) as ./test_executables
or program (in the second case) as ./program
.

- 20,545
- 20
- 91
- 102

- 77
- 2
- 9
If you are using QT5.5
, you can achieve it by adding following lines in your .pro
file.
CONFIG += c++11

- 3,143
- 1
- 32
- 42

- 13
- 2
Using the above solution
g++ -std=c++0x program.cpp
works. However, the command needs to be modified slightly in order to run the program with the common command:
./program
I used
g++ -std=c++0x -o program program.cpp
and all worked perfectly.

- 3,143
- 1
- 32
- 42

- 1
- 1
The best solution is doing this, in Dev C++:
- Go to the "Tools" Option
- Select "Compiler Options"
- Click "Settings"
- Click "Code Generation"
- Go to "Choose Language" and select "ISO C++11"
Then your problem is resolved.

- 49,934
- 160
- 51
- 83
in first time, if you have Dev-C++
C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
, you must add this route to the path
then use the next command in cmd.
g++ -std=c++11 -o outprogram code_source.cpp
this command in your project directory.

- 1
- 1