home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / data / strngtst / strngtst.cpp < prev   
Encoding:
C/C++ Source or Header  |  1996-10-29  |  1.0 KB  |  43 lines

  1. //************************************************************
  2. // Data Types - Using an IStringTest  
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //
  8. // This program takes an input string and finds the first occurrence
  9. // of a blank or punctuation character.
  10. //
  11. //************************************************************
  12. #include <iostream.h>
  13. #include <ctype.h>
  14.  
  15. #include <istring.hpp>
  16. #include <istrtest.hpp>
  17.  
  18. class MyTest : public IStringTest {     
  19.     public:
  20.       MyTest ( )
  21.         : IStringTest( user, 0 )
  22.         {
  23.         }
  24.     virtual int
  25.       test ( int c ) const
  26.         {
  27.         return isspace( c ) || ispunct( c );
  28.         }
  29.     };
  30.  
  31. void main( int argc, char *argv[] )
  32.   {
  33.   if ( argc > 1 )
  34.     {
  35.     IString
  36.       input( argv[1] );
  37.     cout << "The position of the first blank or punctuation is "
  38.          << input.indexOf( MyTest() ) << endl;
  39.     }
  40.   else
  41.     cout << "Enter string to test\a\n";
  42.   }
  43.