FILE IN C++

Maha

FILE IN CPP

           We need to use a second storage device like a hard disk to store the data in real-world problems that handle large amounts of data. Using the concept of files, the data can be stored on these devices.

           A collection of relational data stored in a specific area of the disk is called a file. Read and write operations can be carried out on these files by programs.

           The technique of handling data communications between the console unit and the program. there are methods can available for storing and retrieving the data from files.

           The I/O system of C++ handles file operations which are very much similar to the console input and output operations. It uses file streams as an interface between the program's and the files. The stream that supplies data to the program is know as input stream and the one that receives data from the program is known as output stream.

Classes for file stream operations

The I/O system of C++ contains a set of classes that define the file handling methods. These include ifstream, ofstream and fstream.

  *  Ifstream - It provides input operations. Contains open() with default input mode.Inherits the functions get(), getline(), read(), seekh() and tellg() functions from instream.

  *  ofstream - provides output operations. Contains open() with default output mode. Inherits put(), seekp(), tellp(), and write(), function from ostream.

  *  fstream - provides support for simultaneous input and output operations, Inherits all the functions from istream and ostream classes through iostream 

Opening and closing a file

If we want to use a disk file, we need to decide the following things about the file and it's intended use:

 1. Sutable name for the file

 2. Data type and structure

 3. Purpose (reading, writing data)

 4. Opening method

 5. Closing the file after use





Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send