ostream::write
ostream&  write ( const char* str , streamsize n );
ostream
  cplusplus.com  

Write a sequence of characters.
  Inserts into the output stream a sequence of characters starting by character pointed by str and following by successive characters in the array until the number of characters specified by n has been successfully written or until an error occurs in the output sequence. No check for ending null characters is made.

Parameters.

str
Pointer to the first character of the array to be written.
n
Number of characters to write.

Return Value.
  *this

Example.

// Copy a file
#include <fstream>
using namespace std;

int main () {

  char * buffer;
  long size;

  ifstream infile ("test.txt",ifstream::binary);
  ofstream outfile ("new.txt",ofstream::binary);

  // get size of file
  infile.seekg(0,ifstream::end);
  size=infile.tellg();
  infile.seekg(0);

  // allocate memory for file content
  buffer = new char [size];

  // read content of infile
  infile.read (buffer,size);

  // write to outfile
  outfile.write (buffer,size);

  outfile.close();
  infile.close();
  return 0;
}
  This example copies a file into memory (read) and the writes its content to a new file. (.) is typed.

Basic template member declaration (basic_ostream<charT,traits>):
typedef charT char_type;
basic_ostream& put (const char_type* str, streamsize n);

See also.
  put, operator<<, istream::read,
  ostream class


© The C++ Resources Network, 2001