libstdc++
std::basic_ostringstream Class Reference
Inheritance diagram for std::basic_ostringstream:

List of all members.

Public Types

Public Member Functions

Arithmetic Inserters

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.

Unformatted Output Functions

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.

Protected Member Functions

Friends


Detailed Description

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.


Constructor & Destructor Documentation

std::basic_ostringstream::basic_ostringstream ( ios_base::openmode  __mode = ios_base::out) [inline, explicit]

Default constructor starts with an empty string buffer.

Parameters:
modeWhether 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.

Definition at line 409 of file sstream.

std::basic_ostringstream::basic_ostringstream ( const __string_type __str,
ios_base::openmode  __mode = ios_base::out 
) [inline, explicit]

Starts with an existing string buffer.

Parameters:
strA string to copy as a starting buffer.
modeWhether 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.

Definition at line 427 of file sstream.

std::basic_ostringstream::~basic_ostringstream ( ) [inline]

The destructor does nothing.

The buffer is deallocated by the stringbuf object, not the formatting stream.

Definition at line 438 of file sstream.


Member Function Documentation

void std::basic_ostream::_M_write ( const char_type __s,
streamsize  __n 
) [inline, inherited]

Simple insertion.

Parameters:
cThe character to insert.
Returns:
*this

Tries to insert c.

Note:
This function is not overloaded on signed char and unsigned char.

Definition at line 289 of file ostream.

__ostream_type& std::basic_ostream::flush ( ) [inherited]

Synchronizing the stream buffer.

Returns:
*this

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]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 110 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( __ios_type &(*)(__ios_type &)  __pf) [inline, inherited]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 119 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( ios_base &(*)(ios_base &)  __pf) [inline, inherited]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 129 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 167 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( unsigned long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 171 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( bool  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 175 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( short  __n) [inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These 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]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 182 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( int  __n) [inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These 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]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 193 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 202 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( unsigned long long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 206 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( double  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 211 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( float  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 215 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long double  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 223 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( const void *  __p) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 227 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( __streambuf_type __sb) [inherited]

Extracting from another streambuf.

Parameters:
sbA 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:

  • the input stream reaches end-of-file,
  • insertion into the output sequence fails (in this case, the character that would have been inserted is not extracted), or
  • an exception occurs while getting a character from sb, which sets failbit in the error state

If the function inserts no characters, failbit is set.

__ostream_type& std::basic_ostream::put ( char_type  __c) [inherited]

Simple insertion.

Parameters:
cThe character to insert.
Returns:
*this

Tries to insert c.

Note:
This function is not overloaded on signed char and unsigned char.
__stringbuf_type* std::basic_ostringstream::rdbuf ( ) const [inline]

Accessing the underlying buffer.

Returns:
The current basic_stringbuf buffer.

This hides both signatures of std::basic_ios::rdbuf().

Definition at line 449 of file sstream.

__ostream_type& std::basic_ostream::seekp ( pos_type  ) [inherited]

Changing the current write position.

Parameters:
posA file position object.
Returns:
*this

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.

Parameters:
offA file offset object.
dirThe direction in which to seek.
Returns:
*this

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.

Returns:
rdbuf()->str()

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.

Parameters:
sThe 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.

Returns:
A file position object.

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.

Parameters:
sThe array to insert.
nMaximum number of characters to insert.
Returns:
*this

Characters are copied from s and inserted into the stream until one of the following happens:

  • n characters are inserted
  • inserting into the output sequence fails (in this case, badbit will be set in the stream's error state)
Note:
This function is not overloaded on signed char and unsigned char.

The documentation for this class was generated from the following file: