One huge advantage of C++ streams over C file streams is typed
input and output conversion. In C, the printf
and
scanf
family of subroutines do not perform any parameter
checks. This makes it possible to pass an incorrect parameter.
In the case of scanf
it can easily to memory corruption.
In the case of printf
, if the format string is contructed
from user input, it opens up all kind of vulnerability issues.
None of these problems exist with the C++ streams, as there is no such thing as a format string. All input/output operators are typed.
One slight disadvantage of C++ streams is the difficulty of format
specification. With printf
and scanf
, the specification
of decimal numbers versus hexadecimal numbers is fairly ``quick and
easy''. However, in C++ streams, it involves a bit more code.
Copyright © 2006-10-16 by Tak Auyeung