An istreambuf_iterator
is an iterator adapter that reads raw data from an input stream. Using the ++
operator normally used to advance an iterator instead reads a single unformatted character from the stream. Unlike istream_iterator
, istreambuf_iterator
does not use the <<
operator and consequently ignores formatting. For situations where reading binary data is useful, istreambuf_iterator
is preferable over istream_iterator
.
istreambuf_iterator
is a class template whose template argument indicates what type should be used to store the binary data read from the stream. In virtually all cases, this should be char
.
As with other input iterator classes, you will need two istreambuf_iterator
s to delineate a range. While you can construct an istreambuf_iterator
for any input stream, the STL only defines a single istreambuf_iterator
suitable for use as an end iterator. An istreambuf_iterator
constructed using the default constructor (which has no parameters) creates an istreambuf_iterator
indicating "end of stream." Reading values from such an istreambuf_iterator
results in undefined behavior, so be sure to avoid doing so.
istreambuf_iterator<T>
Member Functionsistreambuf_iterator
that reads from the specified stream.Constructs a new istreambuf_iterator
that reads raw binary data from the specified stream. When the iterator encounters an end of file or the stream enters a fail state, the iterator will take on the sentinel value istreambuf_iterator<T>()
.
istreambuf_iterator
indicating end-of-stream.Constructs a new istreambuf_iterator
that acts as an "end-of-stream" iterator. Use this iterator when defining iterator ranges with an istreambuf_iterator
.
Despite the name of this function, the equal
function does not test whether the two iterators both point to the same element. Instead, it returns true
if both iterators are at end-of-stream or if both iterators are not at end-of-stream.