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

  1. // exios119.cpp
  2. // The istream read function
  3. #include <fstream.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6.  
  7. void main()
  8. {
  9.    struct
  10.    {
  11.       double salary;
  12.       char name[23];
  13.    } employee;
  14.  
  15.    ifstream is( "payroll", ios::binary | ios::nocreate );
  16.    if( is ) {  // ios::operator void*()
  17.       is.read( (char *) &employee, sizeof( employee ) );
  18.       cout << employee.name << ' ' << employee.salary << endl;
  19.    }
  20.    else {
  21.       cout << "ERROR: Cannot open file 'payroll'." << endl;
  22.    }
  23. }
  24.