home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / reverse.pak / REVERSE.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  2KB  |  56 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  REVERSE.CPP                                                           */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1993 Borland International                        */
  6. /*  All Rights Reserved.                                                  */
  7. /*                                                                        */
  8. /*  TStack example file                                                   */
  9. /*                                                                        */
  10. /*------------------------------------------------------------------------*/
  11.  
  12. #if !defined( __STACKS_H )
  13. #include "classlib\stacks.h"
  14. #endif  // __STACKS_H
  15.  
  16. #if !defined( __CSTRING_H )
  17. #include <cstring.h>
  18. #endif  // __CSTRING_H
  19.  
  20. #ifndef __IOSTREAM_H
  21. #include <iostream.h>       
  22. #endif
  23.  
  24. int main()
  25. {
  26.     TStack<string> TheStack;
  27.     string Reverse("reverse");
  28.  
  29.     cout << "\nEnter some strings.  Reverse will collect the strings\n";
  30.     cout << "for you until you enter the string \"reverse\".  Reverse\n";
  31.     cout << "will then print out the strings you have entered, but in\n";
  32.     cout << "reverse order.  Begin entering strings now.\n";
  33.  
  34.     for(;;)
  35.         {
  36.         char InputString[255];
  37.         cin >> InputString;
  38.         string NewString( InputString );
  39.         if( NewString != Reverse )
  40.             {
  41.             TheStack.Push( NewString );
  42.             }
  43.         else 
  44.             {
  45.             break;
  46.             }
  47.         }
  48.  
  49.     cout << "\nThe strings you entered (if any) are:\n";
  50.     while( !(TheStack.IsEmpty()) )
  51.         {
  52.         cout << TheStack.Pop() << endl;
  53.         }
  54.     return 0;
  55. }
  56.