iostream hierarchy
filebuf:: open
  cplusplus.com  
filebuf * open ( const char * s, ios_base::openmode mode );

Open a file.
  Opens a file whose name is s, associating its content with the stream buffer to perform operations allowed by parameter mode.

Parameters.

s
String containg the name of the file to be opened.
mode
Flags describing the requested i/o mode for the file. This is an object of type ios_base::openmode, it generally consist of a combination of the following flags (member constants):
biteffect
app(append) Seek to the end of the stream before each output operation.
ate(at end) Seek to the end of the stream when opening.
binaryConsider stream as binary rather than text.
inAllow input operations on a stream.
outAllow output operations on a stream.
trunc(truncate) Truncate file to zero when opening.

Return Value.
  The function returns this if successful.
  In case of error, function returns a null pointer.

Example.

// filebuf::open ()
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  ifstream is;
  filebuf * fb;

  fb = is.rdbuf();
  fb->open ("test.txt",ios::in);

  // >> file buffer operations here <<

  fb->close();

  return 0;
}

Basic template member declaration ( basic_filebuf<charT,traits> ):
basic_filebuf* open ( const char* s, ios_base::openmode mode );

See also.
  close, is_open
  filebuf class


© The C++ Resources Network, 2001