cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : filebuf : open
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
filebuf
· filebuf::filebuf
· filebuf::~filebuf
member functions:
· filebuf::close
· filebuf::is_open
· filebuf::open
virtual members:
· filebuf::imbue
· filebuf::overflow
· filebuf::pbackfail
· filebuf::seekoff
· filebuf::seekpos
· filebuf::setbuf
· filebuf::showmanyc
· filebuf::sync
· filebuf::uflow
· filebuf::underflow

-

filebuf::open public member function
filebuf * open ( const char * s, ios_base::openmode mode );

Open file

Opens a file whose name is s, associating its content with the stream buffer object to perform input/output operations on it. The operations allowed and some operating details depend on parameter mode.

If the object already has a file associated (open), this function fails.

Parameters

s
C-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 consists of a combination of the following member constants:
flag valueopening mode
app(append) Set the stream's position indicator to the end of the stream before each output operation.
ate(at end) Set the stream's position indicator to the end of the stream on opening.
binary(binary) Consider stream as binary rather than text.
in(input) Allow input operations on the stream.
out(output) Allow output operations on the stream.
trunc(truncate) Any current content is discarded, assuming a length of zero on opening.

Return Value

The function returns this if successful.
In case of failure, close is called and a null pointer is returned.

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

filebuf::is_open Check if a file is open (public member function)
filebuf::close Close file (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us