std::vector<T,Allocator>::back
reference back(); | (1) | |
const_reference back() const; | (2) |
Returns a reference to the last element in the container.
| If | (until C++26) |
| If
| (since C++26) |
Return value
Reference to the last element.
Complexity
Constant.
Notes
For a non-empty container c, the expression c.back() is equivalent to *std::prev(c.end()).
Example
#include <cassert>
#include <vector>
int main()
{
std::vector<char> letters{'a', 'b', 'c', 'd'};
assert(letters.back() == 'd');
}
See also
| access the first element (public member function) |
|
|
(C++11) | returns a reverse iterator to the beginning (public member function) |
|
(C++11) | returns an iterator to the end (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/vector/back