Skip to main content

Section 14.2 Multidimensional Vector Access

To do work with our table, it is important to remember that table is just a vector with three elements (the rows).Using table.size() would produce 3. There are three elements in table. Using table.at(0) would get the first element - the first row of the table.
Figure 14.2.1. table.at(0) selects the first row, which is a vector of integers.
To talk about one element in that row, we need to ask the row for the index we want to work with. table.at(0).at(1) starts by asking the table to give us element 0 (table.at(0)). That is the first row. Then .at(1) asks that row to give us the second element (index 1). The result is a reference to the value at row index 0, column index 1. We can then assign a value to it:
table.at(0).at(1) = 3;
Figure 14.2.2. table.at(0).at(1) = 3 assigns 3 to the first row, second column.
You have attempted of activities on this page.