A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/stack/stack/pop/ below:

public member function

<stack>

std::stack::pop

Remove top element

Removes the element on top of the stack, effectively reducing its size by one.

The element removed is the latest element inserted into the stack, whose value can be retrieved by calling member stack::top.

This calls the removed element's destructor.

This member function effectively calls the member function pop_back of the underlying container object.



Parameters none

Return value none

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// stack::push/pop
#include <iostream>       // std::cout
#include <stack>          // std::stack

int main ()
{
  std::stack<int> mystack;

  for (int i=0; i<5; ++i) mystack.push(i);

  std::cout << "Popping out elements...";
  while (!mystack.empty())
  {
     std::cout << ' ' << mystack.top();
     mystack.pop();
  }
  std::cout << '\n';

  return 0;
}

Output:
Popping out elements... 4 3 2 1 0


Complexity Constant (calling pop_back on the underlying container).

Data races The container and up to all its contained elements are modified.

Exception safety Provides the same level of guarantees as the operation performed on the underlying container object.

See also
stack::push
Insert element (public member function)
stack::empty
Test whether container is empty (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4