The difference between at()
and the operator[]
is that at()
signals if the requested position is out of range by throwing an out_of_range exception.
So with the at()
you can react to the error state. Using the operator[] to access the vector out of index will result in undefined behavior.