Having trouble using range-based for loop in my code, won't compile?

I've been trying to use a range-based for loop in my code but my compiler tells me range based for loops cannot be used in c++98 mode.

I went to settings > compiler and checked the box with "-std = c++11" but now I get a seperate error that opens a new file in my project called stat.h that leads me to an error on a line that says "struct _stat __struct_stat_defined( _off_t, time_t );"

I'm so confused, the compiler i'm using is GNU GCC compiler, on toolchain executables it is mingw32-g++.exe.

Has anyone had this issue before and have any solutions?

Here's the code I was running:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
    {
        const int NUM_SIZE = 5;
        int numbers[NUM_SIZE] = { 1, 5, 6, 9, 10};

        for(int val : numbers)
        {
            cout<<val<<endl;
        }
   return 0;
 }

I've been trying to use a range-based for loop in my code but my compiler tells me range based for loops cannot be used in c++98 mode.

That is correct, range-based loops were added to the standard with the C++11 revision, you need to compile with a C++11 compatible compiler.

I'm so confused, the compiler i'm using is GNU GCC compiler

What is the exact version of the compiler you're using (the compiler, not the IDE)?


Not sure where exactly I would be able to find the name of the compiler, from what I see it's GNU GCC compiler and the file is under MinGW, from what I know the version of code::blocks i'm using is 16.01
Last edited on
I'm not a Windows user so I'm not sure how to check the compiler version with that operating system. But with Linux typing "g++ --version" at a command line prompt spits out the version information. By the way the version of the IDE (code::blocks) has nothing to do with the version of the actual compiler.



It seems that command only works on linux, i'm assuming my gcc is of an older version, do you know where I can find the latest version of MinGW and install it to work with my code::blocks?
After looking into the bin file, I see something named mingw32-gcc-4.9.3

Perhaps this is the version?
Never mind, I finally found a solution, downloaded a new compiler with updated stuff. Had to replace all the paths but it's working fine now. Thank you jlb :)
Topic archived. No new replies allowed.