To get input from a file or send output to a file, you have to create an
ifstream object (for input files) or an
ofstream object (for
output files). These objects are defined in the header file
which you have to include.
A stream is an abstract object that represents the flow of data from a source like the keyboard or a file to a destination like the screen or a file.
We have already worked with two streams:
cin, which has type
cout, which has type
represents the flow of data from the keyboard to the program. Each time
the program uses the
>> operator or the
getline function, it
removes a piece of data from the input stream.
Similarly, when the program uses the
<< operator on an
it adds a datum to the outgoing stream.