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 std::string.
This class supports writing to objects of type std::basic_string, using the inherited functions from std::basic_ostream. To control the associated sequence, an instance of std::basic_stringbuf is used, which this page refers to as sb
.
std::basic_ostringstream::basic_ostringstream | ( | ios_base::openmode | __mode = ios_base::out | ) | [inline, explicit] |
Default constructor starts with an empty string buffer.
mode | Whether the buffer can read, or write, or both. |
ios_base::out
is automatically included in mode.
Initializes sb
using mode|out
, and passes &sb
to the base class initializer. Does not allocate any buffer.
That's a lie. We initialize the base class with NULL, because the string class does its own memory management.
std::basic_ostringstream::basic_ostringstream | ( | const __string_type & | __str, |
ios_base::openmode | __mode = ios_base::out |
||
) | [inline, explicit] |
Starts with an existing string buffer.
str | A string to copy as a starting buffer. |
mode | Whether the buffer can read, or write, or both. |
ios_base::out
is automatically included in mode.
Initializes sb
using str and mode|out
, and passes &sb
to the base class initializer.
That's a lie. We initialize the base class with NULL, because the string class does its own memory management.
std::basic_ostringstream::~basic_ostringstream | ( | ) | [inline] |
void std::basic_ostream::_M_write | ( | const char_type * | __s, |
streamsize | __n | ||
) | [inline, inherited] |
__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.
__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.
__stringbuf_type* std::basic_ostringstream::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.
__string_type std::basic_ostringstream::str | ( | ) | const [inline] |
Copying out the string buffer.
Definition at line 457 of file sstream.
References std::basic_stringbuf::str().
Referenced by std::operator<<().
void std::basic_ostringstream::str | ( | const __string_type & | __s | ) | [inline] |
Setting a new buffer.
s | The string to use as a new sequence. |
Calls rdbuf()->str(s)
.
Definition at line 467 of file sstream.
References std::basic_stringbuf::str().
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: