The I/O Stream Classes and
stdio.h
In both C++ and C, input and output
are described in terms of sequences of characters, or streams.
The I/O Stream Classes provide the same facilities in C++
that stdio.h provides in C, but it also has the following
advantages over stdio.h:
- The input or extraction (>>)
operator and the output or insertion (<<) operator
are typesafe. They are also easy to use.
- You can define input and output for your
own types or classes by overloading the input and output
operators. This gives you a uniform way of performing
input and output for different types of data.
- The input and output operators are more
efficient than scanf() and printf(), the analogous C
functions defined in stdio.h.. Both scanf() and printf()
take format strings as arguments, and these format
strings have to be parsed at run time. This parsing can
be time-consuming. The bindings for the I/O Stream output
and input operators are performed at compile time, with
no need for format strings. This can improve the
readability of input and output in your programs, and
potentially the performance as well.