![]() |
VOOZH | about |
In C++, vector at() is a built-in method used to access an element in a vector using index. It is the only access method that performs bound checking before accessing the element to confirm whether the given index lies is within the vector.
Let’s take a quick look at a simple example that uses vector at() method:
4
This article covers the syntax, usage, and common queries of vector at() method in C++:
Table of Content
The vector at() is a member method of std::vector class defined inside <vector> header file.
v.at(i);
Parameters
Return Value
The below examples illustrate the common uses of vector at() method:
7
Exception: vector::_M_range_check: __n (which is 5) >= this->size() (which is 4)