I’ve a quite simple question but for witch I cannot find the answer.
How can I use the .at(i) in a 2D array of vector < vector <type> > ?
I want to have bounds checking – witch .at(i) function provides automatically, but I can only access my array using the array[i][j] witch doesn’t provide for bounds checking.
Use
vec.at(i).at(j)and must use this intry-catchblock sinceat()will throwstd::out_of_rangeexception if the index is invalid:EDIT:
As you said in the comment:
In that case, you can rethrow in the
catchblock after printing the message that it went out of range, so that you can know the reason why it stopped. And here is how you rethrow: