Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

File copying

This topic is 5832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
IndirectX> mm do you know ctrl+c ?

Read the data of the file and put it into a variable, then write the variable''s data into a new file..

-------------------------------------
"Oasis is not dead !" - WiseMan

Share this post


Link to post
Share on other sites
here ya go:


  
#include <iostream>

#include <fstream>


int main(int argc, char *argv[])
{
if (argc < != 2) cerr << "USAGE: copyfile <src> <dest>" << endl;

ifstream infile(argv[1],ios::in | ios::binary);
if (!infile.is_open()) cerr << "Couldn't open file " << argv1 << " for reading" endl;

infile.seekg(0,ios::end);
int filesize = infile.tellg();
infile.seekg(0,ios::beg);

ofstream outfile(argv[2],ios::out | ios::binary);
if (!outfile.is_open()) cerr " Couldn't open file " << argv[2] << " for writing" << endl;

char *buffer = new char[filesize];
infile.read(buffer,filesize);
outfile.write(buffer,filesize);
delete [] buffer;
return 0;
}


haven't tested it, should work tho

[edited by - barazor on June 2, 2002 11:17:56 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!