|In other words, it will be in the same directory as the exe file.|
No, it might not be.
Since he is running the exe from his IDE, it is more than probable that the file is being created (or trying to be created) in a different directory. And Windows7 is pretty strict about file permissions.
On Windows, the proper place to save files is the user's Application Data folder.
The simplest way to get that folder is to use the APPDATA environment variable.
But you'll have to use a Windows API function to create your saved game data directory.
Here's a function to create everything for you, and an example of how to use it to open a file for writing.
std::string GameFileName( const std::string& filename )
const char* p_appdata = std::getenv( "APPDATA" );
if (!p_appdata) throw 1;
std::string appdata( p_appdata );
appdata.append( "/johnnys-game" );
CreateDirectoryA( appdata.c_str(), NULL );
appdata.append( "/" );
appdata.append( filename );
std::ofstream f( GameFileName( "SavedGame.txt" ).c_str() );
f << "Game progress for Johnny's game.\n";
std::cerr << "Fooey! Could not save game data!\n";
On Windows7, this should create a file named:
is your username -- or the username of whoever is logged on.)
Use it the same way to open a file for reading, using a std::ifstream
instead. Just remember that you cannot open an ifstream on a file that has not already been created.
Hope this helps.
PS. Windows purists, I know about SHGetKnownFolderPath(). And I know about Boost Filesystem. Let's not overload poor OP just yet with a hobbyist game for his friends. The code I posted is fine and safe.