////////////////////////////////////////////////////////////// // // stacktester.cpp // // Shows a few simple uses of the C++ Standard Template // library stack template. // // Jeff Ondich, 1/31/03 // ////////////////////////////////////////////////////////////// #include #include #include int main() { stack theStack; string s; // Build the stack from input. cout << "Type some stuff followed by CTRL-D alone on a line." << endl; while( cin >> s ) { theStack.push( s ); } // Drain the stack, printing its elements as // they are popped. cout << endl << endl; while( theStack.size() > 0 ) { cout << theStack.top() << endl; theStack.pop(); } // You can also create a stack of integers. stack intStack; intStack.push( 123 ); intStack.push( 456 ); intStack.push( 789 ); cout << endl << endl << "The integer stack:" << endl; while( intStack.size() > 0 ) { cout << intStack.top() << endl; intStack.pop(); } return( 0 ); }