Member functions that are used in reading from and writing to Binary file

Member functions that are used in reading from and writing to Binary file

With binary files, when reading and writing, we do not use the operators and functions used with text files because the separation codes used are different an we also do not need to format any data. Below are two member functions used in reading & writing Binary files;

[istream]

read ( memory_block, size );

The read member function of istream that is inherited by ‘ifstream‘. The ‘ifstream‘ is a stream class that writes on files.

In the read function;
– ‘memory_block‘ represents the address of an array of bytes where data elements that will be read will be stored. It is of the type “char *” or “pointer to char“.
– The ‘size‘ parameter is an integer value, which when specified dictates the number of characters that will be read from the memory block at a time, for the ‘read’ function.

 

[ostream]

write ( memory_block, size );

The write member function of ‘ostream‘ that is inherited by ‘ofstream‘. The ‘ofstream‘ is a stream class that writes on files.

In the write function;
– ‘memory_block‘ represents the address of an array of bytes where data elements that will be written are taken. It is of the type ‘char *’ or ‘pointer to char’.
– The ‘size‘ parameter is an integer value, which when specified dictates the number of characters that will be written to the memory block at a time, for the ‘write’ function.

 

Member functions that are used in reading from and writing to Binary file
C++ | thetqweb