C++ File Access Methods - Sequential & Direct Access Methods

- February 01, 2018
The way in which information stored in a data file can be accessed is known as file access method.
 The stored information into data files can be accessed by using different ways. However, the fundamental methods that are commonly used to access
data from files are as follows:

  1. Sequential Access Method 
  2. Direct Access Method 

C++ file handling methods

What is Sequential Access Method?

By using sequential access method, records (or information) are accessed in a sequence. It means records are accessed in order, one after the other. The read and Write operations are performed in a sequential order. Records are read one by one starting from the beginning of data file until the required record is reached or the end of file is reached. It is very slow access method.
The data files in which data is written and read sequentially are known as sequential access files. The sequential access files are also known as formatted . input/output files. In C++, text data files are sequential access data files.

What is Random Access Method?

The process of accessing records directly instead of sequentially is called direct access or random access. It is very fast method to access records. The binary data files in C++ are direct access data files.
Typically, random access can be achieved in one of the two ways:

  • By specifying the location within the file (i. e. bytes number or record number) to be accessed as a parameter to the read or write operation. 
  • By specifying the location in a seek operation before the read or write ' operation.