Home » Archives for October 14th, 2009
Writing and Reading Objects into Files
Writing and Reading Objects into Files:
The objects of a class can also be written into the file on the disk and read back from the file. The objects are written & read in binary format with the “write” member function. Similarly, they are read from the tile with the “read” member function.
When an object is written on the disk into a tile then...
The Read Function in C++
The Read Function:
The “read” function is used to read data or records from the data file into the memory as blocks of bytes. The general syntax of this function is:
object.read ((char*)&rec, sizeof(rec));
where
object: represents the created object of ifstream (or fstream).
read: represents the member function of the created object.
char*: represents data...
The Write Function in C++
The Write Function:
The “write” function writes data or records into a data file in bytes. It writes an object consisting of a block of bytes into the data file. All types of data like struct, array, class object, graphics, etc. can he stored into the tile on the disk by this function. The general syntax of this function is:
object.write ((char*) & rec, sizeof(rec)) ;
Where
object:...
Binary Input Output
Binary Input Output:
In binary input/output, data or records are stored into files in binary format. For example, in binary format, each integer takes two bytes. Thus the integer “30765” will take only two bytes on the disk but in case of formatted input/output, this integer takes 5 bytes of space in the memory as well as on the disk.
The binary format is commonly used to organize large amount...