#include #include #include "stack.h" using namespace std; int main() { cout << "Type a positive integer to push it,\n" << "non-positive to pop the stack,\n" << "control-d to halt.\n\n"; for (stack s;;) { //Construct the stack. cout << "Go ahead: "; int i {0}; cin >> i; if (!cin) { //If the user typed control-d, break; //out of the for loop } if (i > 0) { cout << "Pushing " << i << ".\n"; s.push(i); } else { cout << "Popping " << s.pop() << ".\n"; } } //Arrive here when user types control-d. cout << "The stack has already been destructed.\n"; return EXIT_SUCCESS; }