Assigning values to arrays

I don't understand this warning that I'm getting.

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

using namespace std;

int main(int argc, char * argv[])
{
  double foo [5][5];

  for(int i = 0; i < 5; i++)
  {
    foo[i] = {1, 2, 3, 4, 5};
  }

  for(int x = 0; x < 5; x++)
  {
    for(int y = 0; y < 5; y++)
    {   
      cout << foo[x][y];
    }   

    cout << endl;
  }

  return 0;
}


This is the warning:
warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
It's referring to the boldened part.

What I don't understand is, why is this happening? Should I memcpy instead?
Initializer lists were added in latest version of C++ standard. You should turn it on in your ide preferences/add to compiler launch line.

Alternatively you can use nested loop to assign variables like that:
1
2
3
4
5
for(int i = 0; i < 5; i++)
{
    for(int j = 0; j < 5; ++j)
        foo[i][j] = j + 1;
}


But you should never use memcpy in C++, If you are not handling some low-level hardware stuff. Almost always better to use C++ native method instead of C one.
Topic archived. No new replies allowed.