A program can receive/transfer data from/to
(a) Console I/O
(b) Disk File I/O
Data can be stored in a file using two formats
(a) Binary (b) Character
In binary format 512 takes 2 bytes(16 bits), and in character format it occupies 3 bytes, one for each digit.
In C++, the following hierarchy of classes is defined.
A File can be opened in two ways
(a) Using Constructor (b) Using member Function open().
(a) Using Constructor
Step1: Initialize the first object with a suitable Filename.
Step2: Initialize the File object with a suitable Filename.
Example- ofstream outfile("results"); //output only
ifstream infile("data");//input only
(b) Opening files using open()
General syntax of open() is
Table for file mode parameters
Note:- The modes can be combined as ios::app/ios::nocreate.