You may
work interactively with a program and enter the data each time. However, when
the input data become large, it is necessary to work with a data file rather
than typing the data over and over each time. One example of a data file would
be supermarket pricing, where a huge amount of data is manipulated.
In today’s web engine, hundreds of files may have to be processed in
order to complete a search. The advancement of the Internet has proportionally
increased the number of files and their size.
For any organization, data processing and data manipulation are essential
operations. A database runs the
day-to-day operations by adding new records, searching for particular record(s),
modifying the existing records and generating reports. Due to the real-time
demand of data, the efficiency of databases is subject to review and, as a
result, a tremendous effort has been spent to secure their reliability.
In order to work with a data
file, whether it is to be used to store data or retrieve data, the following
steps need to be taken into consideration.
1) Include the file stream in the header file section.
2) Associate a name with the data file and specify its mode as to whether to output, append or input. This step will open the data file and get it ready.
3) Use the associated file name throughout the program the same way cin and cout are used, except that with cin and cout data are handled by the console (keyboard and screen).
4) Close the file when you are finished.