What
is file handling? Why we use file
handling.
Files permanently.
Before the A file is a collection of related records. A
record contains data about an entity. A file can be used to save any type of
data. Files are stored on secondary storage. The data is stored in start of
using database management system, file handling is used to store data entered
through C++ programs.
Normally when we enter data through C++ programs, it is stored in
variables. If data is long then it can not be entered again and again. There
are certain chances of errors and mistakes while we enter data again and again.
When program ends, the data entered through C++ programs will be lost. Because
they are stored temporarily in variables.
To store our data permanently on secondary storage devices
in a file through C++ programs is called File handling. There are various streams are available to
read and write data to and from the files. fstream, Ifstream,Fstream classes are used to
input data and read data from files.
Ofstream class is used to write on files.
Ifstream class is used to read from files.
Fstream class is used to both read and write data to and
from files.
The
file should be opened before it can be accessed. A file pointer is declared and
associated with the file to be opened. A file can be opened by first creating
an object of ifstream, ofstream, fstream. The object is then associated with
the physical file. An open file is represented by a stream object in a program.
Any input and output operation performed on this stream object is applied to
the physical file associated to it. It helps us to store our data permanently
into files and can be read when ever required.



