Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Binary File Copy

1.22/5 (20 votes)
5 Feb 20071 min read 1   793  
A C++ program to read/write files in binary mode.

Filename : BinaryFileIO.cpp

Author : Pawan Pillai

Description : A C++ program to read/write files in binary mode.
The user itself specifies the number of bytes to be read,
and the code runs a loop until the whole file is copied
at the destination.

Cool points:

1) uses loop to read andd write the bytes, thus clears the concept of reading files when file size is large.

2) shows the use of funtion gcount() whose implementation is missing in most of the tutorials.

3) the user can alter the value of variable "num_of_bytes", thus a value larger than the size of the file can also be used for experimenting purposes.

4) highly commented code, thus clarifies everything in the code.


Info:

the name "umg.rar" is the name of input file, it should be changed to the user specific filename, also the path for sorce file and destination files should also be changed as per requirement.

Lastly:

This is my first code which i am publishing online, just because i thought there are almost no code available online to demonstrate file copy in binary taking a loop. (if there are, then i am sorry).
I hope you like the code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here