tmpl/stest1.cpp

Das folgende Code-Beispiel stammt aus dem Buch
Objektorientiertes Programmieren in C++ - Ein Tutorial für Ein- und Umsteiger
von Nicolai Josuttis, Addison-Wesley München, 2001
© Copyright Nicolai Josuttis 2001


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

int main()
{
    try {
        Bsp::Stack<int>         intStack;       // Stack für Integer
        Bsp::Stack<std::string> stringStack;    // Stack für Strings

        // Integer-Stack manipulieren
        intStack.push(7);
        std::cout << intStack.pop() << std::endl;

        // String-Stack manipulieren
        std::string s = "hallo";
        stringStack.push(s);
        std::cout << stringStack.pop() << std::endl; 
        std::cout << stringStack.pop() << std::endl;
    }
    catch (const char* msg) {
        std::cerr << "Exception: " << msg << std::endl;
        return EXIT_FAILURE;
    }
}