-
coppying files
hey now i'm pretty sure that i got this program perfect theoreticly, but it just wont work! It says virtual memory error when i run the coppied file. If anyone could tell me whats wrong or tell me how to do it any other way i'd appreciate it:
ifstream ifile;
ofstream ofile;
ifile.open("file.exe",ios::binary);
ofile.open("copyd.exe",ios::app);
while(!ifile.eof())
{
ifile.getline(storage,255);
ofile << storage;
}
ifile.close();
ofile.close();
---------------------------------
got any ideas? It looks like it works but it dosnt copy correctly i guess.(??)
-
I don't know much about what you are doing, but the 255 might be the problem.
You might have to increase that number.
-
yeah mich, you need to make it like 1000000 or somthing duh
-
ifstream ifile;
ofstream ofile;
unsigned char uc;
// need storage. what IS storage in your example ?
ifile.open("file.exe",ios::binary);
ofile.open("copyd.exe",ios::binary);
// why appending ? you want a binary copy of a file
while(!ifile.eof())
{
// read a byte, write that byte
ifile >> uc;
ofile << uc;
}
ifile.close();
ofile.close();
-
Ahem, copying a file byte by byte is painfully slow process. One might want to use a few KB buffer instead.
-
You're right... but I thought he'd like to walk before he tries to run :p
-
It would still seem to contain the feof() bug though.
-
right... try this ;) Sorry, I don't have a compiler handy to double check...
ifstream ifile;
ofstream ofile;
unsigned char uc;
ifile.open("file.exe",ios::binary);
ofile.open("copyd.exe",ios::binary);
ifile >> uc;
while(!ifile.eof())
{
ofile << uc;
ifile >> uc;
}
ifile.close();
ofile.close();
-
yea
well i tried makeing them both binary it didnt work either so thats why i left it append.
stoarge variable is what i was going to use to store the data.
like store the first 255 charecters place them down get the next ect.
I tried your program i understand what your trying to do but i get a whole diffrent problem. When i ran the coppied file from my method it said out of virtual memory, when i use your method the copyed file gets an error that it preformd an illeagle operation.
I tested a zip file withy our method, it donst seem to full copy correctly.
Anyway whats this talk about a buffer? if that works i'd like to know. I understand the charecter by charecter i just tried to up do that with my original. I'll keep working on it!
-
Instead of relying on running it, what about copying a textfile first
and searching for any errors by hand ?
This way you will see if there are any bytes ( characters ) missing
or wrongly appended.
If that's correct, I don't see why an executable should not
copy correctly. However if it doesn't, use the commandline tool
FC to compare the original and the copy:
<in a dos window> FC /b file.exe copyd.exe
-
hey tahnk alot!
It wasnt catching spaces(odd?) but i just used:
ifile.get(uc);
and it worked fine! Thanks for the help!