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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

copying binary files c++

Reply to Message Icon

Name: Skr00d
Date: August 18, 2003 at 03:28:41 Pacific
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 :(



Sponsored Link
Ads by Google

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

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;

     }


0

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

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


something...nope nothing ... Software IDE's for linux.



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: copying binary files c++

vb binary file readin and writing www.computing.net/answers/programming/vb-binary-file-readin-and-writing/4232.html

C++ copy / delete file www.computing.net/answers/programming/c-copy-delete-file/10856.html

Text or Binary file using C www.computing.net/answers/programming/text-or-binary-file-using-c/7512.html