#include#include int main() { std::deque mydeque = {1, 2, 3, 4, 5}; std::cout << "Before pop_back: "; for (int i : mydeque) std::cout << i << " "; std::cout << "\nAfter pop_back: "; mydeque.pop_back(); for (int i : mydeque) std::cout << i << " "; return 0; }
Before pop_back: 1 2 3 4 5 After pop_back: 1 2 3 4
#include#include int main() { std::deque mydeque = {1, 2, 3, 4, 5}; std::cout << "Before pop_back: "; for (int i : mydeque) std::cout << i << " "; std::cout << "\nAfter pop_back: "; while (!mydeque.empty()) { mydeque.pop_back(); } for (int i : mydeque) std::cout << i << " "; return 0; }
Before pop_back: 1 2 3 4 5 After pop_back:Both of the above code examples use the std::deque library, which is a part of the C++ Standard Library.