Jump to content
  • Advertisement
Sign in to follow this  
GuitarPlayer0912

Overwriting files

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

Hey, I'm just about finished with a console craps game, and I have an issue with saving files. See, I prompt the user to enter the filename, and then it is saved in the game's directory. But I can't figure out how to compare the new entered filename to one saved in the directory, in which I can use to ask the user if he/she wants to overwrite. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
I would use the functions in boost::filesystem to determine if the file exists. Alternately you can use Windows API functions like FindFirstFile().

edit: A third option is to open the file as an std::ifstream first. If the ifstream() opens the file, the file exists.

Share this post


Link to post
Share on other sites
You can use CreateFile with CREATE_NEW in the dwCreationDisposition parameter and see if it fails.

[edit] Using ifstream is actually a good idea. If you ever want to compile to a different platform, you will have less problems this way.


jfl.

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!