Disk File I/O with Streams| OOP in C++

File Handling

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.

File mode parameters
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()
file-stream-class stream-object;
General syntax of open() is
stream-object•open("Filename", mode);

Table for file mode parameters
File mode
Note:- The modes can be combined as ios::app/ios::nocreate.

Custom Search

%d bloggers like this: