C++, unlike C, has the kinds of services and additions that, at the beginning at least, seem like evil dinosaurs meant to make your life harder and to complicate simple problems. However, once you get the hang of them, you’ll realize the opportunities that they give you, and you won’t ever want to use the older C methods for the same purpose again. Streams are one of these wicked dinosaurs.
Introduction to Streams - Abstract Representation (Page 2 of 4 )
Think of a stream as a consecutive row of data of n numbers. In every cell you can find the data for a specific type, and get it out from in there, once you take it out from the row in which you put it, if you want. But this can also be true in the case of writing a file.
In the end, a text file can be reduced to a flow of words delimited with white spaces. This is sort of like a container that can assure data flow into and out of it (or in just one direction if that is all we need):
From this point of view, the stream is just a temporary container that holds the data until we “consume it.” A database also offers this option. Likewise, C++ also holds some internal streams for devices we use daily on a computer, like the keyboard and mouse as input streams. But a stream can also be a connection between two computers, a file on the disk, or just a string the memory. C++ tries to offer uniform access to all of these.
Let’s see how can we further expand the use of streams. The best example is to see how the keyboard input stream works, something you've already experienced if you code. Here the stream is actually buffered at two levels. First, the input is buffered by the OS into a file so that you don't need to bother with the char pressing message events, and get the input only when and where you want it.
When you request an input, a buffer will be made with the given size limit; the stream library obtains all data available and stores it in a buffer. By minimizing the input calls, most of the operations can be done on the buffer directly.
In C++, I/O (input/output) occurs in streams of bytes. A stream is simply a sequence of bytes. Input streams take any sequence of bytes from a device, while output streams resolve the same in the opposite direction. Because sometimes both operations may need to be used at the same time, there exists the option that a single stream can handle both (by holding inside both types of streams).
C++ provides both "low-level" and "high-level" ways for manipulating streams. Low level commands simply specify the quantity of the bytes to be received from or sent to the stream. High level I/O, on the other hand (also known as formatted I/O), allows the programmer to consider the bytes in the stream as grouped into something that has its own end-result/type, like Int/for/char, for example.
Files are considered just a sequence of bytes, These may be considered "low-level" when read character-by-character (as in a text file) or "high-level" -- for example, in the case of an int value of a file holding the ‘3’ char. Each file is ended by an end of file (eof) marker to indicate the end of the stream/file.
It's doubtful that anyone still considers this a secret: the father of the C++ language, Bjarne Stroustrup, first realized a version of streams back in 1984. Major contributions were made by Jerry Schwarz and Andrew Koenig (in 1989 – better performance and manipulators) and major revisions were made during the ISO C++ standardization process (like adding the support for the local character set).