How do I copy things like ZIP or EXE or DLL files? You can't just load the file word by word then save it word by word, because it just makes the program crash. I need some way to copy files WITHOUT using system(), because that is too slow.
How do I copy things like ZIP or EXE or DLL files? You can't just load the file word by word then save it word by word, because it just makes the program crash. I need some way to copy files WITHOUT using system(), because that is too slow.
You o/s may provide a copyfile function. Alternatively open the file in binary mode, read it into a buffer, write the buffer to the destination, read the next bit into a buffer, etc...
I tried
in_file.open("c:\\test.zip", ios::bin);
but it still crashes. Could you give me some example code?
I have seen other people open binary files with fstream, and it works right for them. The problem right now, is it hangs whenever I load the file.
Ok, here's the short version -
Code:#include <iostream> #include <fstream> using namespace std; int main() { ifstream in("Your.zip",ios::binary); if(!in) cerr << "File open error\n"; ofstream out("Copy.zip",ios::binary); if(!out) cerr << "File open error\n"; out << in.rdbuf(); return 0; }
oops, I was using ios::bin instead of ios::binary
I'll try your source out.