Writing To File Problem


BadKarma

Still Fresh
Joined
Sep 10, 2006
Messages
13
I am making a simple game - I have vector of structures and I want to write values to simple text file.

end of my code :
Code:
		ofstream fout;

					   ...
					   ...

	fout.open(HISCORE_PATH);	
	for (int i = 0; i<=9; i++)
	{
		fout<<hiscore[i].score<<endl;
		fout<<hiscore[i].name<<endl;
	}
	fout.close();
	SDL_Quit();
	
	chdir("/usr/gp2x");
	execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
	
	return 0;
}

I have created a file with pre-defined values (name+score). Program reads values, modifies them and writes them into a text file (the same of course). I can see in main menu that values change. When I exit program to GP2X menu and run program again everything is OK - values are changed. But when I turn off GP2X and start it and run my program values are NOT changed.

Why ?!
 
Sounds like you aren't writing the file to the SD card ?

Have you checked your paths ?
 
Try checking fout.good() to check the file is written ok and the file on the SD card before switching off . (I presume the main menu shows the values from memory rather than the file).
 
the file location is /mnt/sd/Games/Pond2X/data.dat

and HISCORE_PATH is defined as

Code:
#define HISCORE_PATH	"data.dat"

(data.dat is in the same directory as Pond2X.gpe)

Looks like buffer problem to me
 
Add a call to sync() after closing to file. This will actually write the file to the sd card, rather than just being cached in memory.

Alternatively, run the command "sync" from the Linux CLI, or umount the sd card before switching off the power.
 
Back
Top