std::deque<T,Allocator>::pop_back
来自 cppreference.cn
void pop_back(); |
||
移除容器的最后一个元素。
在空容器上调用 pop_back
会导致未定义行为。
指向最后一个元素的迭代器和引用会失效。 end()
迭代器也会失效。
[编辑] 复杂度
常数时间。
[编辑] 示例
运行此代码
#include <deque> #include <iostream> namespace stq { template<typename T> void println(auto, const T& xz) { std::cout << '['; bool first{true}; for (auto const& x : xz) std::cout << (first ? first = false, "" : ", ") << x; std::cout << "]\n"; } } int main() { std::deque<int> numbers{1, 2, 3}; stq::println("{}", numbers); while (not numbers.empty()) { numbers.pop_back(); stq::println("{}", numbers); } }
输出
[1, 2, 3] [1, 2] [1] []
[编辑] 参见
移除第一个元素 (公共成员函数) | |
在末尾添加一个元素 (公共成员函数) |