Sign in to follow this  
jbizzler

Copying Files in C++

Recommended Posts

jbizzler    122
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.

Share this post


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

Share this post


Link to post
Share on other sites
jbizzler    122
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this