Chapter 10. Input-Output Library

Table of Contents

The I/O hierarchy
The elements of iostreams
Define your own streambuffer


Early C++ systems came with a small system of streams, the very first one was designed by Bjarne Stroustrup itself. He has read in the ADA reference that "A non-trivial IO system is impossible to create without specific support of the programming language". He has taken this as a "challenge".

The IOStreams was created for the 2.0 version of the C++ language at 1989. This was the base for the standard comitee, and the foundation of iostreams which is used today.

The main difference between stream i/o and block/record i/o is that stream i/o is unstructured stream of bytes, characters or any other equal size units. The user of iostreams, of course, is free to build up higher structures, like "record", or "message".

The external and the internal representation may differ. The internal representation is that convient for data processing of the program. Common examples are the ASCII code, the IEEE representation of floating point values, and the binary format of integers. The external representation varies depending on the type of the device. Some examples:

  • screen printout is human-readable format of sequence of characters.

  • over a communication channel the data is likely some kind of portable data exchange format.

  • if data is stored on a storage device, it could be compressed, etc...

Depending the data representation we distinguish binary and text I/O.

The stages of the I/O process includes the following steps:

  1. formatting/parsing

  2. buffering

  3. code conversion

  4. transport