libstdc++
|
All the operator<<
functions (aka formatted output functions) have some common behavior. Each starts by constructing a temporary object of type std::basic_ostream::sentry. This can have several effects, concluding with the setting of a status flag; see the sentry documentation for more.
If the sentry status is good, the function tries to generate whatever data is appropriate for the type of the argument.
If an exception is thrown during insertion, ios_base::badbit will be turned on in the stream's error state without causing an ios_base::failure to be thrown. The original exception will then be rethrown.
All the unformatted output functions have some common behavior. Each starts by constructing a temporary object of type std::basic_ostream::sentry. This has several effects, concluding with the setting of a status flag; see the sentry documentation for more.
If the sentry status is good, the function tries to generate whatever data is appropriate for the type of the argument.
If an exception is thrown during insertion, ios_base::badbit will be turned on in the stream's error state. If badbit is on in the stream's exceptions mask, the exception will be rethrown without completing its actions.
Controlling output for files.
This class supports reading from named files, using the inherited functions from std::basic_ostream. To control the associated sequence, an instance of std::basic_filebuf is used, which this page refers to as sb
.
std::basic_ofstream::basic_ofstream | ( | ) | [inline] |
std::basic_ofstream::basic_ofstream | ( | const char * | __s, |
ios_base::openmode | __mode = ios_base::out|ios_base::trunc |
||
) | [inline, explicit] |
Create an output file stream.
s | Null terminated string specifying the filename. |
mode | Open file in specified mode (see std::ios_base). |
ios_base::out|ios_base::trunc
is automatically included in mode.
Tip: When using std::string to hold the filename, you must use .c_str() before passing it to this constructor.
Definition at line 629 of file fstream.
References open().
std::basic_ofstream::basic_ofstream | ( | const std::string & | __s, |
ios_base::openmode | __mode = ios_base::out|ios_base::trunc |
||
) | [inline, explicit] |
Create an output file stream.
s | std::string specifying the filename. |
mode | Open file in specified mode (see std::ios_base). |
ios_base::out|ios_base::trunc
is automatically included in mode.
Definition at line 647 of file fstream.
References open().
std::basic_ofstream::~basic_ofstream | ( | ) | [inline] |
void std::basic_ostream::_M_write | ( | const char_type * | __s, |
streamsize | __n | ||
) | [inline, inherited] |
void std::basic_ofstream::close | ( | ) | [inline] |
Close the file.
Calls std::basic_filebuf::close()
. If that function fails, failbit
is set in the stream's error state.
Definition at line 742 of file fstream.
References std::basic_filebuf::close(), and std::ios_base::failbit.
__ostream_type& std::basic_ostream::flush | ( | ) | [inherited] |
Synchronizing the stream buffer.
If rdbuf()
is a null pointer, changes nothing.
Otherwise, calls rdbuf()->pubsync()
, and if that returns -1, sets badbit.
bool std::basic_ofstream::is_open | ( | ) | [inline] |
Wrapper to test for an open file.
Definition at line 681 of file fstream.
References std::basic_filebuf::is_open().
void std::basic_ofstream::open | ( | const char * | __s, |
ios_base::openmode | __mode = ios_base::out | ios_base::trunc |
||
) | [inline] |
Opens an external file.
s | The name of the file. |
mode | The open mode flags. |
Calls std::basic_filebuf::open
(s,mode|out|trunc). If that function fails, failbit
is set in the stream's error state.
Tip: When using std::string to hold the filename, you must use .c_str() before passing it to this constructor.
Definition at line 702 of file fstream.
References std::basic_filebuf::open(), std::ios_base::out, and std::ios_base::failbit.
Referenced by basic_ofstream().
void std::basic_ofstream::open | ( | const std::string & | __s, |
ios_base::openmode | __mode = ios_base::out | ios_base::trunc |
||
) | [inline] |
Opens an external file.
s | The name of the file. |
mode | The open mode flags. |
Calls std::basic_filebuf::open
(s,mode|out|trunc). If that function fails, failbit
is set in the stream's error state.
Definition at line 723 of file fstream.
References std::basic_filebuf::open(), std::ios_base::out, and std::ios_base::failbit.
__ostream_type& std::basic_ostream::operator<< | ( | __ostream_type &(*)(__ostream_type &) | __pf | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | __ios_type &(*)(__ios_type &) | __pf | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | ios_base &(*)(ios_base &) | __pf | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | long | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | unsigned long | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | bool | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | short | __n | ) | [inherited] |
Basic arithmetic inserters.
A | variable of builtin type. |
*this
if successfulThese functions use the stream's current locale (specifically, the num_get
facet) to perform numeric formatting.
__ostream_type& std::basic_ostream::operator<< | ( | unsigned short | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | int | __n | ) | [inherited] |
Basic arithmetic inserters.
A | variable of builtin type. |
*this
if successfulThese functions use the stream's current locale (specifically, the num_get
facet) to perform numeric formatting.
__ostream_type& std::basic_ostream::operator<< | ( | unsigned int | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | long long | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | unsigned long long | __n | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | double | __f | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | float | __f | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | long double | __f | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | const void * | __p | ) | [inline, inherited] |
__ostream_type& std::basic_ostream::operator<< | ( | __streambuf_type * | __sb | ) | [inherited] |
Extracting from another streambuf.
sb | A pointer to a streambuf |
This function behaves like one of the basic arithmetic extractors, in that it also constructs a sentry object and has the same error handling behavior.
If sb is NULL, the stream will set failbit in its error state.
Characters are extracted from sb and inserted into *this
until one of the following occurs:
If the function inserts no characters, failbit is set.
__ostream_type& std::basic_ostream::put | ( | char_type | __c | ) | [inherited] |
Simple insertion.
c | The character to insert. |
Tries to insert c.
__filebuf_type* std::basic_ofstream::rdbuf | ( | ) | const [inline] |
Accessing the underlying buffer.
This hides both signatures of std::basic_ios::rdbuf().
__ostream_type& std::basic_ostream::seekp | ( | pos_type | ) | [inherited] |
Changing the current write position.
pos | A file position object. |
If fail()
is not true, calls rdbuf()->pubseekpos(pos)
. If that function fails, sets failbit.
__ostream_type& std::basic_ostream::seekp | ( | off_type | , |
ios_base::seekdir | |||
) | [inherited] |
Changing the current write position.
off | A file offset object. |
dir | The direction in which to seek. |
If fail()
is not true, calls rdbuf()->pubseekoff(off,dir)
. If that function fails, sets failbit.
pos_type std::basic_ostream::tellp | ( | ) | [inherited] |
Getting the current write position.
If fail()
is not false, returns pos_type
(-1) to indicate failure. Otherwise returns rdbuf()->pubseekoff(0,cur,out)
.
__ostream_type& std::basic_ostream::write | ( | const char_type * | __s, |
streamsize | __n | ||
) | [inherited] |
Character string insertion.
s | The array to insert. |
n | Maximum number of characters to insert. |
Characters are copied from s and inserted into the stream until one of the following happens: