Sign in to follow this  

Overwriting files

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

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