Say I made a vector matrix: vector<vector<int> > matrix;
and the matrix look likes this:
0,0
0,1
0,2
...
How would I make it get a random piece of this matrix? So for example, how would I get it to access a set of variables like 1,3 like as if it was just an array with stored data in it?
How would I make it get a random piece of this matrix? So for example, how would I get it to access a set of variables like 1,3 like as if it was just an array with stored data in it?
By using one of the various methods of element access defined by the template class with a random value. You can then use those same methods to individually access elements of the returned container.
And finally, member access as though it was "just an array with stored data in it".
matrix[1][3] will also work. This method won't throw an exception if you give index values out of range though , so it is considered by many to be an "unsafe" method.