C/C++ IO are based on streams concept, which are sequence of bytes flowing in and out of the programs . In input operations, data bytes flows from an input source like keyboard, file, network or another program, into the program. In output operations, data bytes flows from the program to an output sink such as console, file, network or another program. Streams acts as intermediaries between the programs and the actual IO devices, in such the way that free the programmers from handling the actual devices, in order to archive device independent IO operations.
To perform output and input, a C++ program:
1. Construct a stream object.
2. Connect (Associate) the stream object to an actual IO device like keyboard, console, file, network, another program.
3. Perform input/output operations on the stream, via functions define in the stream’s pubic interface in a device independent manner. Some functions convert the data between the external format & internal format (formatted IO); while other does not (unformatted or binary IO).
4. Disconnect the stream to the actual IO device that is close the file.
5. Free the stream object.