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; }; int 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 << "> "; } cout << "Here are your " << is.size() << " integers." << endl; 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 << "\nHere are your " << ss.size() << " lines." << 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)); cout << bor.size() << " boring objects on the boring stack." << endl; 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.