Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a stream in C++?

I have been hearing about streams, 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?

like image 552
Mohamed Ahmed Nabil Avatar asked Aug 27 '12 15:08

Mohamed Ahmed Nabil


People also ask

What is file and streams in C?

A file can be: A data set that you can read and write repeatedly. A stream of bytes generated by a program (such as a pipeline). A stream of bytes received from or sent to a peripheral device.

What is stream in C with example?

A stream is a logical entity that represents a file or device, that can accept input or output. All input and output functions in standard C, operate on data streams. Streams can be divided into text, streams and binary streams.

What is stream explain?

Streaming refers to any media content – live or recorded – delivered to computers and mobile devices via the internet and played back in real time. Podcasts, webcasts, movies, TV shows and music videos are common forms of streaming content. Modal.


2 Answers

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.

like image 128
Jonathan Wood Avatar answered Oct 04 '22 21:10

Jonathan Wood


IOStreams are a front-end interface (std::istream, std::ostream) used to define input and output functions. The streams also store formatting options, e.g., the base to use for integer output and hold a std::locale object for all kind of customization. Their most important component is a pointer to a std::streambuf which defines how to access a sequence of characters, e.g., a file, a string, an area on the screen, etc. Specifically for files and strings special stream buffers are provided and classes derived from the stream base classes are provided for easier creation. Describing the entire facilities of the IOStreams library can pretty much fill an entire book: In C++ 2003 about half the library section was devoted to stream related functionality.

like image 28
Dietmar Kühl Avatar answered Oct 04 '22 20:10

Dietmar Kühl