Connect (Associate) the stream object to an actual IO device (e.g., keyboard, console, file, network, another program).To perform input and output, a C++ program: Formatted IO operations are supported via overloading the stream insertion ( >) operators, which presents a consistent public IO interface. In unformatted or low-level IO, bytes are treated as raw bytes and unconverted. In formatted or high-level IO, bytes are grouped and converted to types such as int, double, string or user-defined types.
Streams acts as an intermediaries between the programs and the actual IO devices, in such the way that frees the programmers from handling the actual devices, so as to archive device independent IO operations.Ĭ++ provides both the formatted and unformatted IO functions. In output operations, data bytes flow from the program to an output sink (such as console, file, network or another program). In input operations, data bytes flow from an input source (such as keyboard, file, network or another program) into the program. The same set of operations can be applied to different types of IO devices.Ĭ/C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs (just like water and oil flowing through a pipe). C++ IO operations are based on streams of bytes and are device independent.If IO operations are not defined for a particular type, compiler will generate an error. IO operations are defined for each of the type. C++ continues this approach and formalizes IO in libraries such as iostream and fstream. The ANSI C standard formalized these IO functions into Standard IO package ( stdio.h). Instead, it left the IO to the compiler as external library functions (such as printf and scanf in stdio library). In other words, there is no keyword like read or write. The C language did not build the input/output facilities into the language.