Solved

C++ Program for copying files

Posted on 2003-11-30
13
374 Views
Last Modified: 2010-04-17
I have an exam  and need a simple progam to copy from one file to another in c++ program
I also have to open and close the file
0
Comment
Question by:Roxanne_Hayling
  • 4
  • 2
  • 2
  • +2
13 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 9847070
Sorry, we can't do homework, but if you can post a first stab at the code, we can help out..
0
 
LVL 22

Expert Comment

by:cookre
ID: 9847092
Just like you have to open a book to read or write in it, and you close it when you're done, you do the same thing with files.

To push the metaphor even further, if you're hand copying a book, you might copy one line at a time.

Have you tried surfing for sample code?
0
 
LVL 22

Expert Comment

by:cookre
ID: 9847127
0
 
LVL 1

Expert Comment

by:abhinaysinha
ID: 9852228
The process is to open the file in binary mode, read it an write it the target. I guess I shouldn't send you the code
0
 

Accepted Solution

by:
death_befo_dishonor earned 125 total points
ID: 9854992
i wont send u the source code but here is a tip that might be useful:

open the source file*
open the destination file*

read 1 byte from the source file
write it to the destination file

when there r no bytes left in the source file then close both files... and u done :)

*these must be opened by the binary reader/writer

this method of reading 1 byte at a time is BY FAR the fastest and best way to go about it... it's fast because your program does not need any extra memory except 1 byte

hope this helps... suma
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 22

Expert Comment

by:cookre
ID: 9855113
Uh, folks, I seriously doubt that this elementary assignment has anything to do with binary files.
0
 
LVL 1

Expert Comment

by:abhinaysinha
ID: 9856055
Its true that it does not directly deal with binary files, but opening the file in a binary mode will give a more generalised approach
0
 
LVL 4

Expert Comment

by:void_main
ID: 9856640
One byte at once is easy to implement but it is slooooow. If you read blocks (I use 1024 bytes) the transfer rate will fly up into the sky!!!
0
 

Expert Comment

by:nakhab
ID: 9895403
You can also use "Scripting.FileSystemObject" object for copying file.
FileSystemObject  can be used for all file operations. no need of binary file copy.

find out if you can use this object  in C++. Check for any such libraries

0
 
LVL 4

Expert Comment

by:void_main
ID: 10319744
death_befo_dishonor should earn the points
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 61
countAbc challenge 9 49
SUM 2 INTEGER ARRAYS INTO 1 10 62
C# DataGridView_RowsAdded event not firing 1 40
A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now