Reputation: 11904
I often see people using the term stream but I never get exactly what it means. And what does standard mean? just mean input from terminal and output to terminal? How about stderr? When do we need to use it and what effect it has?
Second, can we create our own stream? And why we need to create it?
Upvotes: 1
Views: 417
Reputation: 299850
In type theory, a stream is just an infinite list of data.
However, in C or C++ it is usually thought of as either an infinite source or an infinite sink. Of course, the infinite is actually a lie most of the times, but it is a useful abstraction as it underlines that the size is unknown.
I think the terms source
and sink
are more useful. You can think of stderr
a sink for characters. From the point of view of the program, it is just something that consumes characters without any apparent effect after all.
You can of course create streams (either sources or sinks or both at the same time).
Upvotes: 2
Reputation: 10808
streams are classes derived from std::ios_base. They present elements one after another compared to random access. You create one by calling the appropriate constructor. If you want to implement your own stream, derive from ios_base and implement all methods accordingly.
Upvotes: 1