tmpl/stest4.cpp

The following code example is taken from the book
Object-Oriented Programming in C++
by Nicolai M. Josuttis, Wiley, 2002
© Copyright Nicolai M. Josuttis 2002


#include <iostream>
#include <string>
#include <cstdlib>
#include "stack4.hpp"

int main()
{
    try {
        CPPBook::Stack<int,20>         int20Stack;   // stack for 20 ints
        CPPBook::Stack<int,40>         int40Stack;   // stack for 40 ints
        CPPBook::Stack<std::string,40> stringStack;  // stack for 40 strings

        // manipulate integer stack
        int20Stack.push(7);
        std::cout << int20Stack.top() << std::endl;
        int20Stack.pop();

        // manipulate string stack
        std::string s = "hello";
        stringStack.push(s);
        std::cout << stringStack.top() << std::endl; 
        stringStack.pop();
        std::cout << stringStack.top() << std::endl;
        stringStack.pop();
    }
    catch (const char* msg) {
        std::cerr << "Exception: " << msg << std::endl;
        return EXIT_FAILURE;
    }
}