
The istream and ostream iterators by themselves have no means of indicating the success or failure of an operation. The stream being operated should be probed for good(), eof(), fail(), or bad() conditions. This is convenient as stream state can be checked for exception conditions that have been set in basic_ios ( void exceptions(iostate except_mask) ) after each input or output operation.
void print()
{
ostream_iterator<int, char, char_traits<char> > os(cout);
try
{
*os = 3; //output `3'
os++; // receive next output
}
catch(ios_base::failure & emsg)
{
cerr<<emsg.what();
}
}
The streambuf iterators provide a member function, failed(), to indicate success or failure in a preceding operation on the stream buffer.
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.