home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / examples / streams / istrstream.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  998 b   |  35 lines

  1. #include <strstream.h>
  2.  
  3. // Example using an istrstream (Input-only String-based stream)
  4. int main(void)
  5. {
  6.    // Declare an istrstream object called "mystream" and initialize
  7.    // it to read bytes from the string "123 456".
  8.    istrstream mystream("123 456");
  9.  
  10.    // Declare a pointer to an istrstream object
  11.    istrstream *stream_p;
  12.  
  13.    int i, j;
  14.    double d;
  15.    char c;
  16.  
  17.    // Read two integers from the string attached to "mystream"
  18.    mystream >> i >> j;
  19.  
  20.    // Print the integers to the program's standard output
  21.    cout << "The integers are " << i << " and " << j << endl;
  22.  
  23.    // Allocate a new static-mode istrstream using "new"
  24.    stream_p = new istrstream("3.765 x");
  25.    *stream_p >> d >> c;
  26.    cout << "The number is " << d << " and the letter is " << c << endl;
  27.  
  28.    // Free the object just allocated.  This will call the destructor
  29.    // for the stream and therefore close the file.
  30.    delete stream_p;
  31.  
  32.    // Destructors for the other streams will automatically be called.
  33.    return 0;
  34. }
  35.