Step Brief Discussion:
We noticed that both C/C++ allow data-segregation, meaning that the
input of data series will be stored in the same order as entered.
The first data will be fetched to the first variable of the input
stream, and so on. In C++language the object cin of istream with
extraction operator, the incorrect data will generate an error and
cin object will fail to entertain the input. As a result cout of
ostream most likely display some unpredicted values.
In the above cases, while testing you codes, if you enter any
character against integer, C compiler might crash, whereas C++ will
Testing Tolerance of iostream class of C++: Note in the
illustration below, I entered a string in the place of an integer,
and as a result the application was terminated due to a
Testing the tolerance of C:
Enter some character against integer value as shown below and then
press return. Note the command window crashed as a result of a
mismatched data type.
I-O Condition states ( ref : http://www.icce.rug.nl/documents/cplusplus/
As we noted above, the stream operation may fail, and to prevent the
crash the streaming operations will be suspended. This measure is most important aspect of data
streaming operations of C++ language. In brief we will view some
machineries of iostream.
The class ios_base is placed on the top of the hierarchies, of
iostream libraries. The class ios which succeeds ios_base, it
communicates other entities with few buffers, and streambuf is one
of those buffers, which plays a key role in orchestrating input-output
operation through all the associated objects. The overall operations
rely on some triggers or conditional-flags, and few are described
• ios::badbit: It is raised at an illegal operation, like matching
failure (like integer vaiable gets alphabets), end of the file or
the file does not exists.
• ios::eofbit: It is raised when end of the file is reached.
• ios::failbit: It is raised when operation could not be performed,
due to wrong data precisions.
• ios::goodbit: when data is good, and none of the above flags were
There are other utilities associated with ios class, we will discuss