home > resources > c++ coding standard > online version

Use Streams

Programmers that move from C to C++ find stream IO strange and prefer the familiarity of good old stdio. Printf and its derivates seem to be more convenient since they are well understood. However when you use these old idioms, you throw away one of the most powerful features of C++.

Justification

Type Safety

Stdio is not type safe, which is one of the reasons you are using C++, right? Stream IO is type safe.

Standard Interface

When you want to dump an object to a stream there is a standard way of doing it: the << operator. This is not true of objects and stdio.

Interchangeablity of Streams

One of the more advanced reasons for using streams is that once an object can dump itself to a stream it can dump itself to any stream. One stream may go to the screen, but another stream may be a serial port or network connection. Good stuff.