I have a 3x3 2D array. I want to reach to all of it's elements. Is it possible? I do this:
int myArray[3][3];
for(int &i: myArray){
//MY CODE HERE.
}
But when I do, I get error:
error: C2440: 'initializing' : cannot convert from 'int [3]' to 'int &'
I also use MSVC++ 2012 compiler on Qt 5.0 x64. And if it's possible to do so, then how can I get the index number of each element?
Just use auto
keyword
int myArray[3][3];
for(auto& rows: myArray) // Iterating over rows
{
for(auto& elem: rows)
{
// do some stuff
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With