Click on the banner to return to the class reference home page.

istreambuf_iterator


istreambuf_iteratorinput_iterator

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <streambuf> 
template<class charT, class traits = char_traits<charT> >
class istreambuf_iterator
: public input_iterator

Description

The template class istreambuf_iterator reads successive characters from the stream buffer for which it was constructed. operator* provides access to the current input character, if any, and operator++ advances to the next input character. If the end of stream is reached, the iterator becomes equal to the end of stream iterator value, which is constructed by the default constructor, istreambuf_iterator(). An istreambuf_iterator object can be used only for one-pass-algorithms.

Interface

template<class charT, class traits = char_traits<charT> >
class istreambuf_iterator
: public input_iterator {

 public:

  typedef charT                          char_type;
  typedef typename traits::int_type      int_type;
  typedef traits                         traits_type;
  typedef basic_streambuf<charT, traits> streambuf_type;
  typedef basic_istream<charT, traits>   istream_type;

  class proxy;  
  
  istreambuf_iterator() throw();
  istreambuf_iterator(istream_type& s)  throw();
  istreambuf_iterator(streambuf_type *s) throw();
  istreambuf_iterator(const proxy& p) throw();

  char_type operator*();
  istreambuf_iterator<charT, traits>& operator++();
  proxy operator++(int);
  bool equal(istreambuf_iterator<charT, traits>& b);

};

template<class charT, class traits>
bool operator==(istreambuf_iterator<charT, traits>& a,
                istreambuf_iterator<charT, traits>& b);

Types

char_type
int_type
istream_type
streambuf_type
traits_type

Nested Class Proxy

Class istreambuf_iterator<charT,traits>::proxy provides a temporary placeholder as the return value of the post-increment operator. It keeps the character pointed to by the previous value of the iterator for some possible future access.

Constructors

istreambuf_iterator() 
  throw();
istreambuf_iterator(istream_type& s)
  throw();
istreambuf_iterator(streambuf_type *s)
  throw();
istreambuf_iterator(const proxy& p)
  throw();

Member Operators

char_type 
operator*();
istreambuf_iterator<charT, traits>& 
operator++();
proxy 
operator++(int);

Public Member Function

bool 
equal(istreambuf_iterator<charT, traits>& b);

Non Member Functions

template<class charT, class traits>
bool 
operator==(istreambuf_iterator<charT, traits>& a,
                istreambuf_iterator<charT, traits>& b);

Examples

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

void main ( )
{
  using namespace std;

  // open the file is_iter.out for reading and writing
  ofstream out("is_iter.out", ios_base::out | ios_base::in );

  // output the example sentence into the file
  out << "Ceci est un simple example pour demontrer le" << endl;
  out << "fonctionement de istreambuf_iterator";

  // seek to the beginning of the file
  out.seekp(0);

  // construct an istreambuf_iterator pointing to
  // the ofstream object underlying stream buffer
  istreambuf_iterator<char> iter(out.rdbuf());

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

  cout << endl;

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

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

  cout << endl;

}

See Also

basic_streambuf(3C++), basic_istream(3C++), ostreambuf_iterator(3C++)

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

Standards Conformance

ANSI X3J16/ISO WG21 Joint C++ Committee


©Copyright 1996, Rogue Wave Software, Inc.