Introduction to Streams
(Page 1 of 4 )
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.
This article is an introduction to my multi-part series that will unveil all of the secrets of streams in C++ and help you get the most benefit from minimal effort. All ten parts will appear here on the Developer Shed network, so stay close and watch out for them.
In this first article I’ll present streams at an abstract level, and explain the purpose for which they were created. Questions like how they should work in general, what convention should be followed so that a class can be called a stream, or why and where to use them won’t be forgotten either.
For this particular article, no object-oriented programming knowledge is required, but if you intend to understand the rest of this series, such knowledge will be mandatory. If you lack these basic ideas in C++ I advise you to first get a good grasp of how classes work, how can they be used, and also what polymorphism represents in the world of codes inside C++.
Taken from the dictionary.com definition, a stream is “a continuous flow or succession of anything: a stream of words.” And of course this fits exactly what a stream wants to be in C++; also, a stream of words can be translated to a stream of ones and zeros if we talk in the language of machines.
Most of the time, streams are used to assure a good and secure flow of data between an application and files. This is why most people simplify them to Input/output streams. However, this is wrong, because streams can be used for many internal procedures within an application as well, as you’ll see during this series. But before we rush further into this subject, let’s consider streams at an abstract level.
Next: Abstract Representation >>
More C++ Articles
More By Gabor Bernat