General Stack Driver
#include <iostream> #include <string> #include <string.h> #include "lstack.h" using namespace std; class Boring { public: Boring(double b) { m_boring = b; } double get() { return m_boring; } private: double m_boring; }; main() { // Make a stack of integers. Stack<int> is; int n; cout << "Enter integers to -1:" << endl << "> "; while(cin >> n) { if(n == -1) break; is.push(n); cout << "> "; } while(!is.empty()) { cout << is.pop() << " "; } cout << endl; // Make a stack of strings. Stack<string> ss; string s; cout << "Enter lines to eof:" << endl << "> "; cin.clear(); getline(cin,s); while(getline(cin,s)) { ss.push(s); cout << "> "; } cout << endl; while(!ss.empty()) { cout << ss.pop() << endl; } // Make a stack of Boring. Stack<Boring> bor; bor.push(Boring(2.45)); bor.push(Boring(-7.3)); bor.push(Boring(0.0)); Boring b(0); while(bor.pop(b)) { cout << b.get() << " "; } cout << endl; // Note that this: // b = bor.pop(); // does not compile. Any idea why? }

This is just a sample user for the stack template class.