Skip to main content
gamedev.net
🔒 Locked

File copying

Started by heavy_bolter 2 replies 500+ views
Original Post
heavy_bolter
heavy_bolter
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.
IndirectX
IndirectX
CopyFile??
---visit #directxdev on afternet <- not just for directx, despite the name
WiseMan
WiseMan
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
-------------------------------------"Oasis is not dead !" - WiseMan
barazor
barazor
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.