Man Page ostreambuf_iterator.3



                       Standard C++ Library
             Copyright 1998, Rogue Wave Software, Inc.



NAME

     ostreambuf_iterator

      - Writes  successive  characters  onto  the  stream  buffer
     object from which it was constructed.





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. operator= is used to write the  characters.  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=(charT c);

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

      bool failed( ) const throw();

     };





TYPES

     char_type


        The type char_type is a synonym for the template  parame-
        ter 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 param-
        eter traits.






CONSTRUCTORS

     ostreambuf_iterator(ostream_type& s) throw();


        Constructs   an   ostreambuf_iterator   that   uses   the
        basic_streambuf  object  pointed to 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 to by s to output charac-
        ters. If s is a null pointer, calls 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 FUNCTIONS

     bool
     failed() const
      throw();


        Returns true if the iterator  failed  while  inserting  a
        character. Otherwise returns false.






EXAMPLE

     //
     // 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++),                  basic_ostream(3C++),
     istreambuf_iterator(3C++)

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





STANDARDS CONFORMANCE

     ANSI X3J16/ISO WG21 Joint C++ Committee