Fstream Not Working Correctly


GP2X_Coder

Member
Joined
May 17, 2006
Messages
220
Age
51
Location
USA
Website
mysite.verizon.net
Sometimes it will write to a text file sometimes it won't. I don't know why does anyone know of a good input output function that is reliable?

Code:
	// Clear the previous log file
	std::fstream DebugFile;
 
	// Set the file name
	sprintf( FileStr, "%slog.txt", GpeDirectory);

	// Open the log and delete the previous written text
	DebugFile.open (FileStr, std::ios::out | std::ios::trunc );

	// Now write something to the file to test it out
	DebugFile << "This is a test."<< "\n";
	DebugFile << "To see if it is writing."<< "\n";

	// Close the log
	DebugFile.close();
 
I believe you just need to sync the filesystem after you finish, try not abusing the command:

sync();

the include you need is in:

#include <unistd.h>
 
Back
Top