Jump to content
  • Advertisement

Archived

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

heavy_bolter

File copying

This topic is 5919 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

G''day all! Something nice and simple today, I want to be able to copy a file from one place to another. How can I go about doing this? Cheers.

Share this post


Link to post
Share on other sites
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!