File Handling In C++ Language

Protected by Copyscape Unique Content Check
Published: 21st September 2011
Views: N/A

File Handling
In this section, we will discuss about files which are very important for large-scale data processing. Data are stored in data files and programs are stored in program files. A file is simply a machine decipherable storage media where programs and data are stored for machine usage. In C++ we say data flows as streams into and out of programs. There are different kinds of streams of data flow for input and output. Each stream is associated with a class, which contains member functions and definitions for dealing with that particular kind of flow. For example, the if stream class represents the input disc files,. Thus each file in C++ is an object of a particular stream class.

The stream class hierarchy

The stream classes are arranged in a rather complex hierarchy. You do not need to understand this hierarchy in detail to program basic file I/O, but a brief overview may be helpful. We have already made extensive use of some of these classes. The extraction operator >> is a member of istream class and the insertion operator is a member of ostream class. Both of these classes are derived from the ios class. The cout object is a predefined object of the ostream with assign class. It is in turn derived from ostream class. The classes used for input and output to the video display and keyboard are declared in the header file IOSTREAM.H, which we have routinely included in all our programs.

Stream classes

The ios class is the base class for the entire I/O hierarchy. It contains many constants and member functions common to input and output operations of all kinds. The istream and ostream classes are derived from ios and are dedicated to input and output respectively Their member functions perform both formatted and unformatted operations. The iostream class is derived from both istream and ostream by multiple inheritance, so that other classes can inherit both of these classes from it. The classes in which we are most interested for file I/O are ifstream for input files ofsteam for output files and fstream for files that will be used for both input and output the ifstream and ofsteam classes are declared in the FSTREAM.H. file.

The isteam class in c language contains input functions such as
getline( )
read( )
and overloaded extraction operators.

The ostream class in c language contains functions such as

Put( )
write( )
and overloaded insertor.

If you want to increase your pc security then learn these PC Tricks and tipsHere you will also get Windows tricks



This article is copyright


Report this article Ask About This Article


Loading...
More to Explore