Click here to Skip to main content
15,890,897 members
Articles / Programming Languages / C++
Article

Binary File Copy

Rate me:
Please Sign up or sign in to vote.
1.22/5 (20 votes)
5 Feb 20071 min read 39.5K   790   14   7
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


Written By
India India
My name is Pawan Pillai.
I am an Information Technology Engineer from India.
I like programming in C, C++ and Java.
My interests are watching movies, playing cricket and table tennis and surfing internet for almost anything.

Comments and Discussions

 
GeneralWorks Perfect Pin
rajmajama24-May-11 15:56
rajmajama24-May-11 15:56 
GeneralThanks Pin
Ident827-Jan-10 17:59
Ident827-Jan-10 17:59 
GeneralMy vote of 1 Pin
Bartosz Wójcik5-Dec-09 13:08
Bartosz Wójcik5-Dec-09 13:08 
GeneralMy vote of 1 Pin
Tsuda Kageyu2-Dec-09 3:46
Tsuda Kageyu2-Dec-09 3:46 
GeneralBinary Copy Code Pin
C++_Rabbit27-Jun-08 16:53
C++_Rabbit27-Jun-08 16:53 
GeneralJust what I was looking for Pin
Rob.Kinney14-Jun-07 8:15
Rob.Kinney14-Jun-07 8:15 
QuestionHow to use ifstream & ofstream with unicode (16 bit wchar_t) file name? Pin
Tongle The Great6-Feb-07 2:25
Tongle The Great6-Feb-07 2:25 
Hello

Thanks for your nice code demonstrating the binary IO of ifstream/ifstream.

Could the standard C++ ifstream/ifstream class be used to open and manipulate
a file with unicode file name (L"filename.abc")? How to use it for such file,
could you explain? Or is ifstream/ifstream incapable of doing that?

Best wishes

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.