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

List of all members.

Classes

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

Protected Attributes

Friends


Detailed Description

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.


Member Typedef Documentation

These are non-standard types.

Reimplemented from std::basic_ios< _CharT, _Traits >.

Definition at line 73 of file ostream.

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.

These are non-standard types.

Reimplemented from std::basic_ios< _CharT, _Traits >.

Definition at line 72 of file ostream.

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 >.

Definition at line 61 of file ostream.

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 >.

Definition at line 62 of file ostream.

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 >.

Definition at line 64 of file ostream.

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 >.

Definition at line 63 of file ostream.

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 >.

Definition at line 65 of file ostream.


Constructor & Destructor Documentation

std::basic_ostream::basic_ostream ( __streambuf_type __sb) [inline, explicit]

Base constructor.

This ctor is almost never called by the user directly, rather from derived classes' initialization lists, which pass a pointer to their own stream buffer.

Definition at line 84 of file ostream.

virtual std::basic_ostream::~basic_ostream ( ) [inline, virtual]

Base destructor.

This does very little apart from providing a virtual base dtor.

Definition at line 93 of file ostream.


Member Function Documentation

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

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.

Referenced by write().

bool std::basic_ios::bad ( ) const [inline, inherited]

Fast error checking.

Returns:
True if the badbit is set.

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.

Parameters:
stateThe 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().

basic_ios& std::basic_ios::copyfmt ( const basic_ios< _CharT, _Traits > &  __rhs) [inherited]

Copies fields of __rhs into this.

Parameters:
__rhsThe source values for the copies.
Returns:
Reference to this object.

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]
iostate std::basic_ios::exceptions ( ) const [inline, inherited]

Throwing exceptions on errors.

Returns:
The current exceptions mask.

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.

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

Returns:
True if either the badbit or the failbit is set.

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.

Returns:
The current fill character.

It defaults to a space (' ') in the current locale.

Definition at line 362 of file basic_ios.h.

References std::basic_ios::widen().

char_type std::basic_ios::fill ( char_type  __ch) [inline, inherited]

Sets a new empty character.

Parameters:
chThe new character.
Returns:
The previous fill 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.

Returns:
*this

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.

Returns:
True if no error flags are set.

A wrapper around rdstate.

Definition at line 172 of file basic_ios.h.

References std::basic_ios::rdstate().

locale std::basic_ios::imbue ( const locale __loc) [inherited]

Moves to a new locale.

Parameters:
locThe new locale.
Returns:
The previous 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.

Parameters:
cThe character to narrow.
dfaultThe character to narrow.
Returns:
The narrowed character.

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]

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]

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]

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]

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]

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]

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.

basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< ( short  __n)

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 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 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.

basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< ( int  __n)

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

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]

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]

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]

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]

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]

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]

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.

basic_ostream< _CharT, _Traits > & std::basic_ostream::operator<< ( __streambuf_type __sb)

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.

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.

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 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 ( basic_streambuf< _CharT, _Traits > *  __sb) [inherited]

Changing the underlying buffer.

Parameters:
sbThe new stream buffer.
Returns:
The previous 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.

Returns:
A bit pattern (well, isn't everything?)

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.

Parameters:
posA file position object.
Returns:
*this

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.

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.

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().

basic_ostream< _CharT, _Traits >::pos_type std::basic_ostream::tellp ( )

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).

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.

Returns:
A pointer to the tied stream, or NULL if the stream is not tied.

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.

Parameters:
tiestrThe output stream.
Returns:
The previously tied output stream, or NULL if the stream was not tied.

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.

Parameters:
cThe character to widen.
Returns:
The widened character.

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.

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.

Definition at line 185 of file ostream.tcc.

References _M_write(), and std::ios_base::badbit.


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