When my book says : a stream is a sequence of characters read or written from a device then my book says : the istream
and the ostream
types represent input and output stream ( what does it mean ?) how exactly do cout
and cin
work?
I'm not a language native and I can't understand when my book says : the output operator writes the given value on the given ostream
.
A stream is a body of water that flows on Earth's surface. The word stream is often used interchangeably with river, though rivers usually describe larger streams.
In simpler terms, streaming is what happens when consumers watch TV or listen to podcasts on Internet-connected devices. With streaming, the media file being played on the client device is stored remotely, and is transmitted a few seconds at a time over the Internet.
A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. The features of Java stream are – A stream is not a data structure instead it takes input from the Collections, Arrays or I/O channels.
A C++ stream is a flow of data into or out of a program, such as the data written to cout or read from cin. For this class we are currently interested in four different classes: istream is a general purpose input stream. cin is an example of an istream.
The fundamental idea behind the metaphor of a "stream" is that it provides or consumes data in a single-pass fashion: for example, for an input stream, data is produced precisely once. You can ask the stream for some more data, and once the stream has given you the data, it will never give you that same data again.
This is why in order to do anything meaningful with streams, you will very usually want to attach a kind of buffer (a "stream buffer", if you will) to the stream which stores some (usually small) amount of data that's been extracted from the stream in a random-access, inspectable and processable piece of memory. (There are similar, reversed ideas for output streams.)
Occasionally it makes sense to process streams without any buffering. For example, if you have an input and an output stream and you read integers from the input and write the doubled value of each integer to the output, you can do that without buffering.
So when thinking about ranges of data, streams are things that you can traverse only once and never again. If you're thinking in terms of forward progress, then streams have another property, which is that they may block: an input stream may block when it has no data, and an output stream may block when it cannot accept any more data. That way, from within the program logic, you can imagine that a input stream always contains data until its end is reached, but a program relying on that may run for an arbitrary, unbounded amount of wall-clock time.
You can define it in simple words as the flow of data which can be the input flow and output flow. So you can think of it as the flow of data from a program to a file or vice versa. The below image may help you understand it better:
From MSDN
The stream is the central concept of the iostream classes. You can think of a stream object as a smart file that acts as a source and destination for bytes. A stream's characteristics are determined by its class and by customized insertion and extraction operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With