EDIT::
Sorry for post i sould google after first page, found it imedietelly.
Hello.
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
1.txt
2.txt
iMadeThisMap.txt
...
//Code
void Map::SaveMap(int mapID)
{
const std::string fileName(glob::MAP_MAP_DIRECTORY + std::to_string(mapID) + ".txt");
//CHECK IF FILE EXISTS HERE
std::ofstream OFStream(fileName);
if(!OFStream.is_open())
{
glob::PrintError("Error at Map::Save error opening map file to save map, file issued to open: " + fileName);
//OR CHECK IF FILE EXISTS HERE
...
return;
}
}
For solution:
http://stackoverflow.com/questions/4316442/stdofstream-check-if-file-exists-before-writing