命名空间
变体
操作

std::list<T,Allocator>::pop_back

来自 cppreference.cn
< cpp‎ | 容器‎ | list
 
 
 
 
void pop_back();

移除容器的最后一个元素。

在空容器上调用 pop_back 会导致未定义行为。

指向被移除元素的引用和迭代器会失效。

[edit] 复杂度

常数。

[edit] 示例

#include <list>
#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::list<int> numbers{1, 2, 3};
    stq::println("{}", numbers);
    while (not numbers.empty())
    {
        numbers.pop_back();
        stq::println("{}", numbers);
    }
}

输出

[1, 2, 3]
[1, 2]
[1]
[]

[edit] 参见

移除第一个元素
(public member function) [edit]
在末尾添加一个元素
(public member function) [edit]