Advertisement Jump to content
Sign in to follow this  

Saving files with std::ofstream checking if filename alredy exists to prompt "Are you sure you want to overwrite"

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

Sorry for post i sould google after first page, found it imedietelly.



Currently i am making mapeditor.

At point where a user presses "Save map" he is prompted to enter a name for the map.

After he is done entering the map name i want to check if the filename alredy exists, in case it alredy exists i want to prompt to user a overwrite command that there is a file with that name already, or allow him to retype the name.

The issue is i do not know how to check if file exists i only know how to open and write to it.

//FOLDER with maps
void Map::SaveMap(int mapID)
    const std::string fileName(glob::MAP_MAP_DIRECTORY + std::to_string(mapID) + ".txt");
    std::ofstream OFStream(fileName);
        glob::PrintError("Error at Map::Save error opening map file to save map, file issued to open: " + fileName);

For solution:

Edited by rip-off

Share this post

Link to post
Share on other sites

Please do not mark posts as "solved".

Thank you for doing it instead of me.

Can you link me to a page with rules or so, i do not want to make accidents like this.

Tried searching for it and googling something like " topic rules" on my end gave me just topics unrelated to rules.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!