Jump to content
  • Advertisement
Sign in to follow this  
jbizzler

Copying Files in C++

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

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
Sign in to follow this  

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