The classical iostreams hierarchy
The <stdio.h>
API suffers from at least three problems. First, the formatting functionality is far from type-safe. Second, the buffering functionality is awkwardly split up into "buffering into a file stream" (FILE *
and fprintf
) and "buffering into a character buffer" (snprintf
). (Okay, technically, the GNU C library provides fopencookie
to construct FILE *
that buffers into anything you want; but this is fairly obscure and extremely non-standard.) Third, there is no easy way to extend the formatting functionality for user-defined classes; I cannot even printf
a std::string
, let alone my::Widget
!
When C++ was being developed in the mid-1980s, the designers felt a need for a type-safe, composable, and extensible I/O library. Thus was born the feature known as "iostreams," or simply as "C++ streams" (not to be confused with the <stdio.h>
streams we just finished talking about). The fundamental architecture of iostreams has not changed since the...