Namespaces
Variants
Views
Actions

std::basic_filebuf::open

From cppreference.com
< cpp‎ | io‎ | basic filebuf
Revision as of 22:40, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
std::basic_filebuf<CharT, Traits>* open( const char* s, std::ios_base::openmode mode )
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
std::basic_filebuf<CharT, Traits>* open( const std::string& s, std::ios_base::openmode mode )
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Opens the file whose name is given by

1) the null-terminated narrow byte string s

2) the null-terminated narrow byte string s.c_str()

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 Template:rlpf and returns a null pointer to indicate failure.

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

Contents

Parameters

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

Return value

*this on success, a null pointer on failure.

Notes

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

Example

See also

Template:cpp/io/basic filebuf/dcl list is openTemplate:cpp/io/basic filebuf/dcl list close