Test stack method: push(), empty(), top(), pop() - C++ STL

C++ examples for STL:stack

Description

Test stack method: push(), empty(), top(), pop()

Demo Code

#include <iostream>
#include <string>
#include <queue>
#include <stack>
using namespace std;
int main()// w ww . ja  va 2 s  .  com
{
   stack<char> stck;
   cout << "Demonstrate a stack for characters.\n";
   cout << "Pushing  A, B, C, and D.\n";
   stck.push('A');
   stck.push('B');
   stck.push('C');
   stck.push('D');
   cout << "Now, retrieve those values in LIFO order.\n";
   while(!stck.empty()) {
      cout << "Popping: ";
      cout << stck.top() << "\n";
      stck.pop();
   }
   return 0;
}

Result


Related Tutorials