std::vector<T,Allocator>::pop_back
void pop_back(); | (constexpr since C++20) |
Removes the last element of the container.
| If | (until C++26) |
| If
| (since C++26) |
Iterators and references to the last element are invalidated. The end() iterator is also invalidated.
Complexity
Constant.
Example
#include <vector>
#include <print>
int main()
{
std::vector<int> numbers{1, 2, 3};
for (; not numbers.empty(); numbers.pop_back())
std::println("{}", numbers);
}
Output:
[1, 2, 3] [1, 2] [1]
See also
| adds an element 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/pop_back