#include #include #include "stack.h" using namespace std; int main() { stack s; cout << "Type a positive integer to push it,\n" << "0 or negative to pop the stack,\n" << "control-d to halt.\n"; for (;;) { cout << "Go ahead: "; int i {0}; cin >> i; if (!cin) { //If the user typed control-d break; //out of the for loop } try { if (i > 0) { s.push(i); } else { cout << s.pop() << "\n";; } } catch (out_of_range &out) { cerr << out.what() << "\n"; cerr << "Try again.\n"; } } return EXIT_SUCCESS; }