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.
This is the base class for all output streams. It provides text formatting of all builtin types, and communicates with any class derived from basic_streambuf to do the actual output.
typedef ctype<_CharT> std::basic_ostream::__ctype_type |
These are non-standard types.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > std::basic_ios::__num_get_type [inherited] |
These are non-standard types.
Reimplemented in std::basic_istream.
Definition at line 88 of file basic_ios.h.
typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > std::basic_ostream::__num_put_type |
These are non-standard types.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef _CharT std::basic_ostream::char_type |
These are standard types. They permit a standardized way of referring to names of (or names dependant on) the template parameters, which are specific to the implementation.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef _Traits::int_type std::basic_ostream::int_type |
These are standard types. They permit a standardized way of referring to names of (or names dependant on) the template parameters, which are specific to the implementation.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef _Traits::off_type std::basic_ostream::off_type |
These are standard types. They permit a standardized way of referring to names of (or names dependant on) the template parameters, which are specific to the implementation.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef _Traits::pos_type std::basic_ostream::pos_type |
These are standard types. They permit a standardized way of referring to names of (or names dependant on) the template parameters, which are specific to the implementation.
Reimplemented from std::basic_ios< _CharT, _Traits >.
typedef _Traits std::basic_ostream::traits_type |
These are standard types. They permit a standardized way of referring to names of (or names dependant on) the template parameters, which are specific to the implementation.
Reimplemented from std::basic_ios< _CharT, _Traits >.
std::basic_ostream::basic_ostream | ( | __streambuf_type * | __sb | ) | [inline, explicit] |
virtual std::basic_ostream::~basic_ostream | ( | ) | [inline, virtual] |
void std::basic_ostream::_M_write | ( | const char_type * | __s, |
streamsize | __n | ||
) | [inline] |
bool std::basic_ios::bad | ( | ) | const [inline, inherited] |
Fast error checking.
Note that other iostate flags may also be set.
Definition at line 203 of file basic_ios.h.
References std::basic_ios::rdstate(), and std::ios_base::badbit.
void std::basic_ios::clear | ( | iostate | __state = goodbit | ) | [inherited] |
[Re]sets the error state.
state | The new state flag(s) to set. |
See std::ios_base::iostate for the possible bit values. Most users will not need to pass an argument.
Referenced by std::basic_istream::putback(), std::basic_istream::unget(), and std::basic_istream::seekg().
Copies fields of __rhs into this.
__rhs | The source values for the copies. |
All fields of __rhs are copied into this object except that rdbuf() and rdstate() remain unchanged. All values in the pword and iword arrays are copied. Before copying, each callback is invoked with erase_event. After copying, each (new) callback is invoked with copyfmt_event. The final step is to copy exceptions().
bool std::basic_ios::eof | ( | ) | const [inline, inherited] |
Fast error checking.
Note that other iostate flags may also be set.
Definition at line 182 of file basic_ios.h.
References std::basic_ios::rdstate(), and std::ios_base::eofbit.
Referenced by std::basic_istream::sentry::sentry(), std::basic_istream::get(), std::basic_istream::getline(), std::basic_istream::ignore(), std::basic_istream::peek(), std::basic_istream::putback(), std::basic_istream::unget(), std::operator>>(), and std::ws().
iostate std::basic_ios::exceptions | ( | ) | const [inline, inherited] |
Throwing exceptions on errors.
This changes nothing in the stream. See the one-argument version of exceptions(iostate) for the meaning of the return value.
Definition at line 214 of file basic_ios.h.
void std::basic_ios::exceptions | ( | iostate | __except | ) | [inline, inherited] |
Throwing exceptions on errors.
except | The new exceptions mask. |
By default, error flags are set silently. You can set an exceptions mask for each stream; if a bit in the mask becomes set in the error flags, then an exception of type std::ios_base::failure is thrown.
If the error flag is already set when the exceptions mask is added, the exception is immediately thrown. Try running the following under GCC 3.1 or later:
#include <iostream> #include <fstream> #include <exception> int main() { std::set_terminate (__gnu_cxx::__verbose_terminate_handler); std::ifstream f ("/etc/motd"); std::cerr << "Setting badbit\n"; f.setstate (std::ios_base::badbit); std::cerr << "Setting exception mask\n"; f.exceptions (std::ios_base::badbit); }
Definition at line 249 of file basic_ios.h.
References std::basic_ios::clear().
bool std::basic_ios::fail | ( | ) | const [inline, inherited] |
Fast error checking.
Checking the badbit in fail() is historical practice. Note that other iostate flags may also be set.
Definition at line 193 of file basic_ios.h.
References std::basic_ios::rdstate(), std::ios_base::badbit, and std::ios_base::failbit.
Referenced by std::basic_istream::tellg(), std::basic_istream::seekg(), tellp(), and seekp().
char_type std::basic_ios::fill | ( | ) | const [inline, inherited] |
Retrieves the empty character.
It defaults to a space (' ') in the current locale.
Definition at line 362 of file basic_ios.h.
References std::basic_ios::widen().
Sets a new empty character.
ch | The new character. |
The fill character is used to fill out space when P+ characters have been requested (e.g., via setw), Q characters are actually used, and Q<P. It defaults to a space (' ') in the current locale.
Definition at line 382 of file basic_ios.h.
References std::basic_ios::fill().
basic_ostream< _CharT, _Traits > & std::basic_ostream::flush | ( | ) |
Synchronizing the stream buffer.
If rdbuf()
is a null pointer, changes nothing.
Otherwise, calls rdbuf()->pubsync()
, and if that returns -1, sets badbit.
Definition at line 213 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::rdbuf(), std::ios_base::badbit, and std::basic_ios< _CharT, _Traits >::setstate().
Referenced by std::flush(), and std::basic_ostream::sentry::sentry().
bool std::basic_ios::good | ( | ) | const [inline, inherited] |
Fast error checking.
A wrapper around rdstate.
Definition at line 172 of file basic_ios.h.
References std::basic_ios::rdstate().
Moves to a new locale.
loc | The new locale. |
Calls ios_base::imbue(loc)
, and if a stream buffer is associated with this stream, calls that buffer's pubimbue(loc)
.
Additional l10n notes are at http://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html
void std::basic_ios::init | ( | basic_streambuf< _CharT, _Traits > * | __sb | ) | [protected, inherited] |
All setup is performed here.
This is called from the public constructor. It is not virtual and cannot be redefined.
Referenced by std::basic_istream< char >::basic_istream(), and std::basic_ostream< char >::basic_ostream().
char std::basic_ios::narrow | ( | char_type | __c, |
char | __dfault | ||
) | const [inline, inherited] |
Squeezes characters.
c | The character to narrow. |
dfault | The character to narrow. |
Maps a character of char_type
to a character of char
, if possible.
Returns the result of
std::use_facet<ctype<char_type> >(getloc()).narrow(c,dfault)
Additional l10n notes are at http://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html
Definition at line 422 of file basic_ios.h.
std::basic_ios::operator void * | ( | ) | const [inline, inherited] |
The quick-and-easy status check.
This allows you to write constructs such as if (!a_stream) ...
and while (a_stream) ...
Definition at line 113 of file basic_ios.h.
References std::basic_ios::fail().
bool std::basic_ios::operator! | ( | ) | const [inline, inherited] |
The quick-and-easy status check.
This allows you to write constructs such as if (!a_stream) ...
and while (a_stream) ...
Definition at line 117 of file basic_ios.h.
References std::basic_ios::fail().
__ostream_type& std::basic_ostream::operator<< | ( | __ostream_type &(*)(__ostream_type &) | __pf | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | __ios_type &(*)(__ios_type &) | __pf | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | ios_base &(*)(ios_base &) | __pf | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | long | __n | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | unsigned long | __n | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | bool | __n | ) | [inline] |
basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< | ( | short | __n | ) |
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.
Definition at line 94 of file ostream.tcc.
References std::ios_base::oct, and std::ios_base::hex.
__ostream_type& std::basic_ostream::operator<< | ( | unsigned short | __n | ) | [inline] |
basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< | ( | int | __n | ) |
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.
Definition at line 108 of file ostream.tcc.
References std::ios_base::oct, and std::ios_base::hex.
__ostream_type& std::basic_ostream::operator<< | ( | unsigned int | __n | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | long long | __n | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | unsigned long long | __n | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | double | __f | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | float | __f | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | long double | __f | ) | [inline] |
__ostream_type& std::basic_ostream::operator<< | ( | const void * | __p | ) | [inline] |
basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< | ( | __streambuf_type * | __sb | ) |
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.
Definition at line 122 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::rdbuf(), std::ios_base::badbit, std::ios_base::failbit, and std::basic_ios< _CharT, _Traits >::setstate().
basic_ostream< _CharT, _Traits > & std::basic_ostream::put | ( | char_type | __c | ) |
Simple insertion.
c | The character to insert. |
Tries to insert c.
Definition at line 151 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::rdbuf(), std::basic_streambuf::sputc(), std::ios_base::badbit, and std::basic_ios< _CharT, _Traits >::setstate().
Referenced by std::endl(), and std::ends().
basic_streambuf<_CharT, _Traits>* std::basic_ios::rdbuf | ( | ) | const [inline, inherited] |
Accessing the underlying buffer.
This does not change the state of the stream.
Definition at line 313 of file basic_ios.h.
Referenced by std::basic_istream::operator>>(), std::basic_istream::get(), std::basic_istream::getline(), std::basic_istream::ignore(), std::basic_istream::peek(), std::basic_istream::read(), std::basic_istream::readsome(), std::basic_istream::putback(), std::basic_istream::unget(), std::basic_istream::sync(), std::basic_istream::tellg(), std::basic_istream::seekg(), std::basic_ostream< char >::_M_write(), operator<<(), put(), flush(), tellp(), and seekp().
basic_streambuf<_CharT, _Traits>* std::basic_ios::rdbuf | ( | basic_streambuf< _CharT, _Traits > * | __sb | ) | [inherited] |
Changing the underlying buffer.
sb | The new stream buffer. |
Associates a new buffer with the current stream, and clears the error state.
Due to historical accidents which the LWG refuses to correct, the I/O library suffers from a design error: this function is hidden in derived classes by overrides of the zero-argument rdbuf()
, which is non-virtual for hysterical raisins. As a result, you must use explicit qualifications to access this function via any derived class. For example:
std::fstream foo; // or some other derived type std::streambuf* p = .....; foo.ios::rdbuf(p); // ios == basic_ios<char>
iostate std::basic_ios::rdstate | ( | ) | const [inline, inherited] |
Returns the error state of the stream buffer.
See std::ios_base::iostate for the possible bit values. Most users will call one of the interpreting wrappers, e.g., good().
Definition at line 129 of file basic_ios.h.
Referenced by std::basic_istream::putback(), std::basic_istream::unget(), and std::basic_istream::seekg().
basic_ostream< _CharT, _Traits > & std::basic_ostream::seekp | ( | pos_type | __pos | ) |
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.
Definition at line 260 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::fail(), std::basic_ios< _CharT, _Traits >::rdbuf(), std::basic_streambuf::pubseekpos(), std::ios_base::out, std::ios_base::badbit, and std::basic_ios< _CharT, _Traits >::setstate().
basic_ostream< _CharT, _Traits > & std::basic_ostream::seekp | ( | off_type | __off, |
ios_base::seekdir | __dir | ||
) |
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.
Definition at line 292 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::fail(), std::basic_ios< _CharT, _Traits >::rdbuf(), std::basic_streambuf::pubseekoff(), std::ios_base::out, std::ios_base::badbit, and std::basic_ios< _CharT, _Traits >::setstate().
void std::basic_ios::setstate | ( | iostate | __state | ) | [inline, inherited] |
Sets additional flags in the error state.
state | The additional state flag(s) to set. |
See std::ios_base::iostate for the possible bit values.
Definition at line 149 of file basic_ios.h.
References std::basic_ios::clear(), and std::basic_ios::rdstate().
Referenced by std::basic_istream::operator>>(), std::basic_istream::get(), std::basic_istream::getline(), std::basic_istream::ignore(), std::basic_istream::peek(), std::basic_istream::read(), std::basic_istream::readsome(), std::basic_istream::putback(), std::basic_istream::unget(), std::basic_istream::sync(), std::basic_istream::seekg(), std::basic_ostream< char >::_M_write(), operator<<(), put(), flush(), and seekp().
basic_ostream< _CharT, _Traits >::pos_type std::basic_ostream::tellp | ( | ) |
Getting the current write position.
If fail()
is not false, returns pos_type
(-1) to indicate failure. Otherwise returns rdbuf()->pubseekoff(0,cur,out)
.
Definition at line 239 of file ostream.tcc.
References std::basic_ios< _CharT, _Traits >::fail(), std::basic_ios< _CharT, _Traits >::rdbuf(), std::basic_streambuf::pubseekoff(), std::ios_base::cur, std::ios_base::out, and std::ios_base::badbit.
basic_ostream<_CharT, _Traits>* std::basic_ios::tie | ( | ) | const [inline, inherited] |
Fetches the current tied stream.
A stream may be tied (or synchronized) to a second output stream. When this stream performs any I/O, the tied stream is first flushed. For example, std::cin
is tied to std::cout
.
Definition at line 287 of file basic_ios.h.
basic_ostream<_CharT, _Traits>* std::basic_ios::tie | ( | basic_ostream< _CharT, _Traits > * | __tiestr | ) | [inline, inherited] |
Ties this stream to an output stream.
tiestr | The output stream. |
This sets up a new tie; see tie() for more.
Definition at line 299 of file basic_ios.h.
char_type std::basic_ios::widen | ( | char | __c | ) | const [inline, inherited] |
Widens characters.
c | The character to widen. |
Maps a character of char
to a character of char_type
.
Returns the result of
std::use_facet<ctype<char_type> >(getloc()).widen(c)
Additional l10n notes are at http://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html
Definition at line 441 of file basic_ios.h.
Referenced by std::basic_istream< char >::get(), and std::basic_istream< char >::getline().
basic_ostream< _CharT, _Traits > & std::basic_ostream::write | ( | const char_type * | __s, |
streamsize | __n | ||
) |
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:
Definition at line 185 of file ostream.tcc.
References _M_write(), and std::ios_base::badbit.