August 2012
Intermediate to advanced
976 pages
30h 17m
English
for with Multidimensional ArraysUnder the new standard we can simplify the previous loop by using a range for:
size_t cnt = 0;for (auto &row : ia) // for every element in the outer array for (auto &col : row) { // for every element in the inner array col = cnt; // give this element the next value ++cnt; // increment cnt }
This loop gives the elements of ia the same values as the previous loop, but this time we let the system manage the indices for us. We want to change the value of the elements, so we declare our control variables, row and col, as references (§ 3.2.3, p. 93). The ...
Read now
Unlock full access