Thread: Copying binary files, like ZIPs

  1. #1

    Copying binary files, like ZIPs

    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.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    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...

  3. #3
    I tried"c:\\", 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.

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Ok, here's the short version -

    #include <iostream> 
    #include <fstream>
    using namespace std;
    int main()
    	ifstream in("",ios::binary);
    		cerr << "File open error\n";
    	ofstream out("",ios::binary);
    		cerr << "File open error\n";
    	out << in.rdbuf();
    	return 0;

  5. #5
    oops, I was using ios::bin instead of ios::binary

    I'll try your source out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying Files
    By HLA91 in forum C++ Programming
    Replies: 8
    Last Post: 10-25-2007, 03:24 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Copying Binary Files
    By mikeman118 in forum C++ Programming
    Replies: 9
    Last Post: 08-11-2007, 10:55 PM
  4. Help with binary files
    By tuxinator in forum C Programming
    Replies: 3
    Last Post: 12-01-2005, 02:11 AM
  5. fstream binary files
    By wesdgreat in forum C++ Programming
    Replies: 1
    Last Post: 01-29-2003, 10:12 PM