istream&  read (char* s, streamsize n );

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.


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

Return Value.
  The functions return *this


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

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

  ifstream is; ("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: (buffer,length);


  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