This C++ program illustrates usage of a adaptor called stack. An adapter is a data type that adapts a container to provide specific interface. Stack provides facility to push elements into it and pop them.
Here is the source code of the C++ program illustrates usage of stack. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Illustrate Stack Adaptor
std::stack< char > s;
// Pushing elements into stack
for (char c = 'a'; c <= 'f'; c++)
std::cout << "Top element of stack \'" << s.top()
<< "\'" << std::endl;
std::cout << "Stack is empty!" << std::endl;
$ ./a.out Top element of stack 'f' Top element of stack 'e' Top element of stack 'd' Top element of stack 'c' Top element of stack 'b' Top element of stack 'a' Stack is empty!
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs.