std::basic_filebuf::open - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::basic_filebuf::open

From cppreference.com
< cpp‎ | io‎ | basic filebuf

std::basic_filebuf<CharT, Traits>* open( const char* s, std::ios_base::openmode mode ) | (1) |
std::basic_filebuf<CharT, Traits>* open( const std::string& str, std::ios_base::openmode mode ) | (2) | (since C++11)

Opens the file with the given name - either `s` or str.c_str().

The file is opened as if by calling std::fopen(s, modestring), where `modestring` is determined as follows:

modestring | openmode & ~ate
"r" | `in`
"w" | `out`, out|trunc
"a" | `app`, out|app
"r+" | out|in
"w+" | out|in|trunc
"a+" | out|in|app, in|app
"rb" | binary|in
"wb" | binary|out, binary|out|trunc
"ab" | binary|app, binary|out|app
"r+b" | binary|out|in
"w+b" | binary|out|in|trunc
"a+b" | binary|out|in|app, binary|in|app

If `openmode` is not one of the modes listed, the `open()` fails.

If the open operation succeeds and openmode & std::ios_base::ate != 0 (the `ate` bit is set), repositions the file position to the end of file, as if by calling std::fseek(file, 0, SEEK_END). If the repositioning fails, calls close() and returns a null pointer to indicate failure.

If the associated file was already open, returns a null pointer right away.

### [edit] Parameters

s, str | - | the file name to open
openmode | - | the file opening mode, a binary OR of the std::ios_base modes

### [edit] Return value

this on success, a null pointer on failure.

### [edit] Notes

`open()` is typically called through the constructor or the `open()` member function of std::basic_fstream.

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

is_open | checks if the associated file is open (public member function) [edit]
close | flushes the put area buffer and closes the associated file (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_filebuf/open&oldid=67949"
Category:

- Todo no example