Computing.Net > Forums > Programming > copying binary files c++

copying binary files c++

Reply to Message Icon

Original Message
Name: Skr00d
Date: August 18, 2003 at 03:28:41 Pacific
Subject: copying binary files c++
OS: WinME
CPU/Ram: 60
Comment:

i am trying to write a program that can copy a binary file (exe). nothing i have tried has worked, i initially tried to copy the entire file into a character array but i assume binary files use characters that make the compiler prematurely terminate the string. the closest i have come so far is

fstream outfile("write.exe", ios::out|ios::binary|ios::trunc);
for (counter=0;counter> x;
outfile x;
}

where endf is the length of the file to be copied. this almost works but the resultng program makes an illegal error immediately on startup. i have been searching the net for hours and can't figure this one out :(


Report Offensive Message For Removal


Response Number 1
Name: Skr00d
Date: August 18, 2003 at 03:32:35 Pacific
Reply: (edit)

i didnt realize code doesnt post on here. what i meant to post was

fstream outfile("write.exe", ios::out|ios::binary|ios::trunc);

     for (counter=0;counter> x;

         outfile  x;

     }


Report Offensive Follow Up For Removal

Response Number 2
Name: zeroguy
Date: August 18, 2003 at 21:09:30 Pacific
Reply: (edit)

I'm not sure if you've already tried this, but I think it would make things a whole lot simpler if you just used a system call like cp for nix, or it's DOS equivelant copy. I *think* you can do that with just SYSTEM("copy [source file] [dest file]"); in DOS, but I'm not sure. Try looking up how to call DOS command-line calls if that doesn't work.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: copying binary files c++

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge