home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c063 / 3.ddi / CLASSEXM.ZIP / REVERSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-18  |  1.1 KB  |  47 lines

  1. #if !defined( __STACK_H )
  2. #include <Stack.h>
  3. #endif    // __STACK_H
  4.  
  5. #if !defined( __STRNG_H )
  6. #include <Strng.h>
  7. #endif    // __STRNG_H
  8.  
  9. #ifndef __IOSTREAM_H
  10. #include <iostream.h>       
  11. #endif
  12.  
  13. int main()
  14. {
  15.     Stack theStack;
  16.     String reverse("reverse");
  17.  
  18.     cout << "\nEnter some strings.  Reverse will collect the strings\n";
  19.     cout << "for you until you enter the string \"reverse\".  Reverse\n";
  20.     cout << "will then print out the strings you have entered, but in\n";
  21.     cout << "reverse order.  Begin entering strings now.\n";
  22.  
  23.     for(;;)
  24.         {
  25.         char inputString[255];
  26.         cin >> inputString;
  27.         String& newString = *( new String( inputString ) );
  28.         if( newString != reverse )
  29.             {
  30.             theStack.push( newString );
  31.             }
  32.         else 
  33.             {
  34.             break;
  35.             }
  36.         }
  37.  
  38.     cout << "\nThe strings you entered (if any) are:\n";
  39.     while( !(theStack.isEmpty()) )
  40.         {
  41.         Object& oldString = theStack.pop();
  42.         cout << oldString << "\n";
  43.         delete &oldString;
  44.         }
  45.     return 0;
  46. }
  47.