|
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 value | opening 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// 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
|