.\" ident @(#)ostreambuf_iterator.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH ostreambuf_iterator 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2ostreambuf_iterator\fP \ - Writes successive characters onto the stream buffer object from which it was constructed. .SH SYNOPSIS .RE .RS 0 #include .br template > .br class ostreambuf_iterator .br : public output_iterator .SH DESCRIPTION The template class ostreambuf_iterator writes successive characters onto the stream buffer object from which it was constructed. \f2operator=\fP is used to write the characters. In case of failure, the member function \f2failed()\fP returns \f2true\fP. .SH INTERFACE .br template > .br class ostreambuf_iterator .br : public output_iterator { .br .br public: .br .RE .RS 1 typedef charT char_type; .br typedef traits traits_type; .br typedef basic_streambuf streambuf_type; .br typedef basic_ostream ostream_type; .RE .RS 0 .RE .RS 1 ostreambuf_iterator(ostream_type& s) throw(); .br ostreambuf_iterator(streambuf_type *s) throw(); .br ostreambuf_iterator& operator=(charT c); .RE .RS 0 .RE .RS 1 ostreambuf_iterator& operator*(); .br ostreambuf_iterator& operator++(); .br ostreambuf_iterator operator++(int); .RE .RS 7 .RE .RS 1 bool failed( ) const throw(); .RE .RS 4 .RE .RS 0 }; .SH TYPES .br char_type .RE .RS 3 The type \f2char_type\fP is a synonym for the template parameter \f2charT\fP. .RE .br ostream_type .RE .RS 3 The type \f2ostream_type\fP is an instantiation of class \f2basic_ostream\fP on types \f2charT\fP and \f2traits\fP: \f2typedef basic_ostream ostream_type;\fP .RE .br streambuf_type .RE .RS 3 The type \f2streambuf_type\fP is an instantiation of class \f2basic_streambuf\fP on types \f2charT\fP and \f2traits\fP: \f2typedef basic_streambuf streambuf_type;\fP .RE .br traits_type .RE .RS 3 The type \f2traits_type\fP is a synonym for the template parameter \f2traits\fP. .RE .SH CONSTRUCTORS .br ostreambuf_iterator(ostream_type& s) throw(); .RE .RS 3 Constructs an \f2ostreambuf_iterator\fP that uses the \f2basic_streambuf \fPobject pointed to by \f2s.rdbuf()\fPto output characters. If \f2s.rdbuf()\fP is a null pointer, calls to the member function \f2failed()\fP return \f2true\fP. .RE .br ostreambuf_iterator(streambuf_type *s) throw(); .RE .RS 3 Constructs an \f2ostreambuf_iterator\fP that uses the \f2basic_streambuf \fPobject pointed to by \f2s\fP to output characters. If \f2s\fP is a null pointer, calls the member function\f2 failed()\fP return \f2true\fP. .RE .SH MEMBER OPERATORS .br ostreambuf_iterator& .br operator=(charT c); .RE .RS 3 Inserts the \f2character\fP \f2c\fP into the output sequence of the attached stream buffer. If the operation fails, calls to the member function \f2failed()\fP return \f2true\fP. .RE .br ostreambuf_iterator& .br operator++(); .RE .RS 3 Returns \f2*this\fP. .RE .br ostreambuf_iterator .br operator++(int); .RE .RS 3 Returns \f2*this\fP. .RE .br ostreambuf_iterator .br operator*(); .RE .RS 3 Returns \f2*this\fP. .RE .SH PUBLIC MEMBER FUNCTIONS .br bool .br failed() const .RE .RS 1 throw(); .RE .RS 3 Returns \f2true\fP if the iterator failed while inserting a character. Otherwise returns \f2false\fP. .RE .SH EXAMPLE .RE .RS 0 // .br // stdlib/examples/manual/ostreambuf_iterator.cpp .br // .br #include .br #include .br .br void main ( ) .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 2 // create a filebuf object .RE .RS 1 filebuf buf; .RE .RS 0 .RE .RS 2 // open the file iter_out and link it .br // to the filebuf object .RE .RS 1 buf.open("iter_out", ios_base::in | ios_base::out ); .RE .RS 0 .RE .RS 2 // create an ostreambuf_iterator and link it to .br // the filebuf object .RE .RS 1 ostreambuf_iterator out_iter(&buf); .RE .RS 0 .RE .RS 2 // output into the file using the ostreambuf_iterator .RE .RS 1 for(char i=64; i<128; i++ ) .RE .RS 2 out_iter = i; .RE .RS 0 .RE .RS 2 // seek to the beginning of the file .RE .RS 1 buf.pubseekpos(0); .RE .RS 2 .br // create an istreambuf_iterator and link it to .br // the filebuf object .RE .RS 1 istreambuf_iterator in_iter(&buf); .RE .RS 0 .RE .RS 2 // construct an end of stream iterator .RE .RS 1 istreambuf_iterator end_of_stream_iterator; .RE .RS 0 .RE .RS 1 cout << endl; .RE .RS 0 .RE .RS 2 // output the content of the file .RE .RS 1 while( !in_iter.equal(end_of_stream_iterator) ) .RE .RS 0 .RE .RS 2 // use both operator++ and operator* .RE .RS 1 cout << *in_iter++; .RE .RS 0 .RE .RS 1 cout << endl; .RE .RS 0 .br } .SH 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 .SH STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee