0

Here is the code:

int myarray[3] = {10,20,30};
  for (int elem : myarray)
    cout << elem << '\n';

if I compile like this:

g++ test.cpp

I get an error

test.cpp:12:17: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for (int elem : myarray)
                ^
2 warnings generated.
Era Freddy
  • 45
  • 2
  • 7
  • 1
    This gave me no issues under C++11 and -Wall flag. You are not correctly using C++11. `g++ -Wall -g -std=c++11 your_file.cpp -o your_program` – dh4ze Mar 29 '20 at 15:32
  • Related if not a duplicate: [https://stackoverflow.com/questions/45291142/what-is-a-c11-extension-wc11-extensions/45291997](https://stackoverflow.com/questions/45291142/what-is-a-c11-extension-wc11-extensions/45291997) – drescherjm Mar 29 '20 at 15:35
  • It's time to update your compiler. – anastaciu Mar 29 '20 at 15:40
  • It's `-std=c++11` for C++11 support, not `-Wc++11`. See my answer below. – Jesper Juhl Mar 29 '20 at 15:43

2 Answers2

0
g++ -Wall -g -std=c++11 your_file.cpp -o your_program

You are still not properly compiling under C++11.

dh4ze
  • 449
  • 1
  • 5
  • 10
-2

so add '-std=c++11' to your compiler command line arguments

edwinc
  • 1,658
  • 1
  • 14
  • 14