File Input/Output
In C++, file input/output services are implemented through a component header file available C++ standard library. This header file is fstream.h .
In C++, a file, at its lowest level, is interpreted simply as a sequence, or stream, of bytes. One aspect of the file I/O library manages the transfer of these bytes. At this level, the concept of a data type is absent. On the other hand, file, at the user level, consists of a sequence of possibly intermixed data types – characters, arithmetic values, class objects etc. A second aspect of file I/O library manages the interface between these two levels.
The fstream.h Header File
The C++ input/output operations are very much similar to the console input and output operations. The file operations also make use of streams as an interface between the programs and the files.
A stream is a general name given to a flow of data. Different streams are used to represent different kinds of data flow. Each stream is associated with a particular class, which contains member functions and definitions for dealing with that particular kind of data flow. For example, the ifstream class represents input disk files.
The stream that supplies data to the program is known as input stream. It reads data from a file and hands it over to the program. The stream that receives data from the program is known as the output stream. It writes the received data to the file.

In C++, to open a file, you must first obtain a stream. There are three types of streams: input, output, and input/output. To create an input stream, you must declare the stream to be of class ifstream. To create an output stream, you must declare it as class ofstream. Streams that would perform both input and output operations must be declared as class fstream. Once a stream has been created, next step is to associate a file with it. Thereafter the file is available (opened) for processing.
Opening of a file can be achieved in two ways:
- Using the constructor function of the stream class.
- Using the function called open( ).
The first method is preferred when a single file is used with a stream; however, for managing multiple files with the same stream, the second method is preferred.
Opening a File using Constructor
A constructor of a class initializes an object of its class when it (the object) is being created. Same way, a constructor of stream class (ifstream, ofstream, or fstream) is used to initialize a file stream object with the filename/s passed to them. To open a d ata file, as an input file, we shall create a file stream object of input type i.e., ifstream type.
The above given statement creates an object (i.e. input-file) of input file stream. The object name is a user defined name (i.e., any valid identifier). After creating the ifstream object inpt-file, the file DataFile is opened and attached to the input stream object inpt-file. The data being read from DataFile is been channelized through the input stream object.

Example: An illustration about opening a file using constructor
Output:

- SDIO (Secure Digital Input/Output)
The Secure Digital Input/Output card standard expands upon the original Secure Digital card standard, extending the functionality of many devices with SD card slots. The Secure Digital Input/Output card standard is based on the Secure Digital standard. The SD flash memory format was designed purely for portable storage; many cell phones, cameras, GPS receivers and [...]...
- File Manipulation
A file is basically a set of records stored on your computer's secondary memory. There may be situations requiring a program to open more than one file. The strategy for opening multiple files depends upon how they will be used. If the situation requires simultaneous processing of two files, then you need to create a [...]...
- PIO (Programmed Input/Output)
PIO is Programmed I/O. PIO is the oldest method is transferring memory over a IDE/ATA interface. The technique of a PIO involves using the CPU and support hardware to control the transfer of memory between the system itself and the hard drive. The speed of the PIO is called a PIO Mode. It starts at [...]...
- BIOS (Basic Input/Output System)
BIOS or Basic Input/Output System is the first program that the processor accesses during start up to ensure that all the other basic programs, hard drives, ports, peripherals, and the central processing unit are in good working condition. BIOS is different from the computer’s operating system. The operating system is inside the hard drive and [...]...
- Lossless Compression
Lossless compression is any compression format where all information in the imput stream is preversed in the output stream. Audio Formats which use Lossless Compression Lossless compression is less commonly utilized in computer audio file formats than lossy compression. Audio file formats which use lossless compression include: Free Lossless Audio Codec (FLAC) ALAC Direct Stream [...]...




