United States    
COMPAQ STORE | PRODUCTS | SERVICES | SUPPORT
| CONTACT US | SEARCH
C++
ostreambuf_iterator (3C++std) - Tru64 UNIX
Standard C++ Library
Copyright 1996, Rogue Wave Software, Inc.

NAME

  ostreambuf_iterator

SYNOPSIS

  #include <streambuf>
  template<class charT, class traits = char_traits<charT> >
  class ostreambuf_iterator
  : public output_iterator

DESCRIPTION

  The template class ostreambuf_iterator writes successive characters onto
  the stream buffer object from which it was constructed. The operator= is
  used to write the characters and in case of failure the member function
  failed() returns true.

INTERFACE

  template<class charT, class traits = char_traits<charT> >
  class ostreambuf_iterator
  : public output_iterator {

  public:

   typedef charT                          char_type;
   typedef traits                         traits_type;
   typedef basic_streambuf<charT, traits> streambuf_type;
   typedef basic_ostream<charT, traits>   ostream_type;

   ostreambuf_iterator(ostream_type& s) throw();

   ostreambuf_iterator(streambuf_type *s) throw();

   ostreambuf_iterator& operator*();
   ostreambuf_iterator& operator++();
   ostreambuf_iterator operator++(int);

   ostreambuf_iterator& operator=(charT c);

   bool failed( ) const throw();

  };

TYPES

  char_type
     The type char_type is a synonym for the template parameter charT.

  ostream_type
     The type ostream_type is an instantiation of class basic_ostream on
     types charT and traits:

       typedef basic_ostream<charT, traits>   ostream_type;

  streambuf_type
     The type streambuf_type is an instantiation of class basic_streambuf on
     types charT and traits:

       typedef basic_streambuf<charT, traits> streambuf_type;

  traits_type
     The type traits_type is a synonym for the template parameter traits.

CONSTRUCTORS

  ostreambuf_iterator(ostream_type& s) throw();
     Constructs an ostreambuf_iterator that uses the basic_streambuf object
     pointed at by s.rdbuf()to output characters. If s.rdbuf() is a null
     pointer, calls to the member function failed() return true.

  ostreambuf_iterator(streambuf_type *s) throw();
     Constructs an ostreambuf_iterator that uses the basic_streambuf object
     pointed at by s to output characters. If s is a null pointer, calls to
     the member function failed() return true.

MEMBER OPERATORS

  ostreambuf_iterator&
  operator=(charT c);
     Inserts the character c into the output sequence of the attached stream
     buffer. If the operation fails, calls to the member function failed()
     return true.

  ostreambuf_iterator&
  operator++();
     Returns *this.

  ostreambuf_iterator
  operator++(int);
     Returns *this.

  ostreambuf_iterator
  operator*();
     Returns *this.

PUBLIC MEMBER FUNCTION

  bool
  failed() const
   throw();
      Returns true if the iterator failed inserting a characters or false
      otherwise.

EXAMPLES

  //
  // stdlib/examples/manual/ostreambuf_iterator.cpp
  //
  #include<iostream>
  #include<fstream>

  void main ( )
  {
   using namespace std;

    // create a filebuf object
   filebuf  buf;

    // open the file iter_out and link it to the filebuf object
   buf.open("iter_out", ios_base::in | ios_base::out );

    // create an ostreambuf_iterator and link it to
    // the filebuf object
   ostreambuf_iterator<char> out_iter(&buf);

    // output into the file using the ostreambuf_iterator
   for(char i=64; i<128; i++ )
    out_iter = i;

    // seek to the beginning of the file
   buf.pubseekpos(0);

    // create an istreambuf_iterator and link it to
    // the filebuf object
   istreambuf_iterator<char> in_iter(&buf);

    // construct an end of stream iterator
   istreambuf_iterator<char> end_of_stream_iterator;

   cout << endl;

    // output the content of the file
   while( !in_iter.equal(end_of_stream_iterator) )

    // use both operator++ and operator*
   cout << *in_iter++;

   cout << endl;

  }

SEE ALSO

  basic_streambuf(3C++std), basic_ostream(3C++std),
  istreambuf_iterator(3C++std)

  Working Paper for Draft Proposed International Standard for Information
  Systems--Programming Language C++, Section 24.4.4

STANDARDS CONFORMANCE

  ANSI X3J16/ISO WG21 Joint C++ Committee
  

1.800.AT.COMPAQ

privacy and legal statement