Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
stack
comparison operators
stack::stack
member functions:
stack::empty
stack::pop
stack::push
stack::size
stack::top


stack::pop

public member function
void pop ( );

Remove element

Removes the element on top of the stack, effectively reducing its size by one. The value of this element can be retrieved before being popped 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 (such as deque::pop_back).

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
21
// stack::push/pop
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
  stack<int> mystack;
  for (int i=0; i<5; ++i) mystack.push(i);
  cout << "Popping out elements...";
  while (!mystack.empty())
  {
     cout << " " << mystack.top();
     mystack.pop();
  }
  cout << endl;
  return 0;
}


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


Complexity

Constant.

See also