read

C/C++ Reference

read
Syntax:
  #include <fstream>
  istream& read( char* buffer, streamsize num );

The function read() is used with input streams, and reads num bytes from the stream before placing them in buffer. If EOF is encountered, read() stops, leaving however many bytes it put into buffer as they are.

For example:

   struct {
     int height;
     int width;
   } rectangle;         

   input_file.read( (char *)(&rectangle), sizeof(rectangle) );
   if( input_file.bad() ) {
     cerr << "Error reading data" << endl;
     exit( 0 );
   }            
Related topics: