Sign in to follow this  

Copying Files in C++

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

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
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
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

This topic is 3873 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.

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