istream::read
istream&  read (char* s, streamsize n );
istream
  cplusplus.com  

Read a block of data.
  Reads a block of data of the length specified by n. Data is read sequentially, so if the End-Of-File is reached before the whole block could be read the buffer will contain the elements read until End-Of-File.

Parameters.

s
Pointer to an array of characters to be read.
n
Integer value of type streamsize representing the size of the block to be read.

Return Value.
  The functions return *this

Example.

// read a file into memory
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  int length;
  char * buffer;

  ifstream is;
  is.open ("test.txt", ios::binary );

  // get length of file:
  is.seekg (0, ios::end);
  length = is.tellg();
  is.seekg (0, ios::beg);

  // allocate memory:
  buffer = new char [length];

  // read data as a block:
  is.read (buffer,length);

  is.close();

  cout.write (buffer,length);

  return 0;
}

Basic template member declaration ( basic_istream<charT,traits> ):
typedef charT char_type;
basic_istream& read ( char_type* s, streamsize n );

See also.
  get, operator>>
  istream class


© The C++ Resources Network, 2001