I am learning C++ and I have a problem with struct and arrays. My struct is:
struct board
{
string name;
string desc;
int nval;
int sval;
int eval;
int wval;
};
My array looks like this:
board field[10][10];
I’m able to do for example:
field[5][6].name = "ExampleName";
field[5][6].desc = "This is an example";
field[5][6].nval = 3;
//and so on...
But I want to assign to the whole structure at once, something like this:
field[5][6] = {"ExampleName", "This is an example", 3, 4, 5, 6};
//so I don't have to type everything over and over again...
What you are trying to do is allowed in C standard. It seems to be working in C++ as well. I verified it in C++11:
It’s printing correctly. So you should be able to do that.