home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / IOSTUTOR / EXIOS116.CP$ / EXIOS116
Encoding:
Text File  |  1991-11-25  |  670 b   |  32 lines

  1. // exios116.cpp
  2. // The istream get member function
  3. #include <iostream.h>
  4.  
  5. void main()
  6. {
  7.    char line[100], ch = 0, *cp;
  8.  
  9.    cout << " Type a line terminated by 'x'\n>";
  10.    cp = line;
  11.    while ( ch != 'x' )
  12.    {
  13.       cin >> ch;
  14.       if( !cin.good() ) break; // Exits on EOF or failure
  15.       *cp++ = ch;
  16.    }
  17.    *cp = '\0';
  18.    cout << ' ' << line;
  19.    cin.seekg( 0L, ios::end ); // Empties the input stream
  20.    cout << "\n Type another one\n>";
  21.    cp = line;
  22.    ch = 0;
  23.    while ( ch != 'x' )
  24.    {
  25.       cin.get( ch );
  26.       if( !cin.good() ) break; // Exits on EOF or failure
  27.       *cp++ = ch;
  28.    }
  29.    *cp = '\0';
  30.    cout << ' ' << line;
  31. }
  32.