C++: What is a stream

Mohamed Ahmed Nabil picture Mohamed Ahmed Nabil · Aug 27, 2012 · Viewed 33.6k times · Source

I have been hearing about stream, more specifically file streams.

So what are they?

Is it something that has a location in the memory?

Is it something that contains data?

Is it just a connection between a file and an object?

Any help would be appreciated

Answer

Jonathan Wood picture Jonathan Wood · Aug 27, 2012

The term stream is an abstraction of a construct that allows you to send or receive an unknown number of bytes. The metaphor is a stream of water. You take the data as it comes, or send it as needed. Contrast this to an array, for example, which has a fixed, known length.

Examples where streams are used include reading and writing to files, receiving or sending data across an external connection. However the term stream is generic and says nothing about the specific implementation.