Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

basic_ostream Class 

This template class describes an object that controls insertion of elements and encoded objects into a stream buffer with elements of type Elem, also known as char_type, whose character traits are determined by the class Tr, also known as traits_type.

For a list of all members of this type, see basic_ostream Members.


template <class _Elem, class _Tr = char_traits<Elem> >
   class basic_ostream
       : virtual public basic_ios<_Elem, _Tr>

Parameters

_Elem

A char_type.

_Tr

The character traits_type.

Most of the member functions that overload operator<< are formatted output functions. They follow the pattern:

   iostate state = goodbit;
   const sentry ok( *this );
   if ( ok )
      {try
         {<convert and insert elements
         accumulate flags in state> }
      catch ( ... )
         {try
           {setstate( badbit ); }
         catch ( ... )
           {}
         if ( ( exceptions( ) & badbit ) != 0 )
           throw; }}
   width( 0 );    // Except for operator<<(Elem)
   setstate( state );
   return ( *this );

Two other member functions are unformatted output functions. They follow the pattern:

   iostate state = goodbit;
   const sentry ok( *this );
   if ( !ok )
      state |= badbit;
   else
      {try
         {<obtain and insert elements
         accumulate flags in state> }
      catch ( ... )
         {try
            {setstate( badbit ); }
         catch ( ... )
            {}
         if ( ( exceptions( ) & badbit ) != 0 )
            throw; }}
   setstate( state );
   return ( *this );

Both groups of functions call setstate(badbit) if they encounter a failure while inserting elements.

An object of class basic_istream<Elem, Tr> stores only a virtual public base object of class basic_ios<Elem, Tr>.

See the example for basic_ofstream Class to learn more about output streams.

Header: <ostream>

Community Additions

ADD
Show:
© 2015 Microsoft