Copying Files in C++

Started by
1 comment, last by jbizzler 17 years ago
How can I copy a file in C++? I'm trying to make a program check if it has a settings file, and if it doesn't, copy the defSettings file to it. I'm just using fstream, no ASP or MFC or anything. If I could just get the size of defSettings, I could write it's contents to settings real easy.
Advertisement
First way to do this that came to my mind is to open the file you want to copy, then open a fstream where you want to copy to. And then just read the source file and then write it to the destination file. Do this in binary mode though.
That was my problem; I wasn't doing it in binary mode. Thanks.

FYI, if anyone ever needs the size of a file, here's how I did it.

defSettings.seekg(0, ios_base::end);
size_t size = defSettings.tellg();
defSettings.seekg(0, ios_base::beg);

This topic is closed to new replies.

Advertisement