View Single Post
std::fstream Is not writing :(
Old
  (#1)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default std::fstream Is not writing :( - 25-02-2005

This is making me go insane, for some reason nothing is being written when I call std::fstream::write or std::fstream::put.
It's gotta be something simple but I'm just not seeing it, thanks in advance for any help .

Code:
// Opens the crash check file, returns true if success
bool CCrashFile_HL1::Open( void ) {
   char szPath[ 256 ];		// Path to crashstatus.bin

   // Get the game directory
   GET_GAME_DIR( szPath );

   // Append the crashstatus.bin path and fix the path for win32
   strncat( szPath, "/crashstatus.bin", sizeof( szPath ) );
   CMapcycle_HL1::FixpathWin32( szPath ); // Note: Now I remember why I made this static method public....

   // Try and open crashstatus.bin in read only mode to see if it exists
   m_fCrashstatus = new std::fstream( szPath, std::ios.in | std::ios.binary );

   // If allocation failed, exit now
   if ( ! m_fCrashstatus )
	  return false;

   // If the file wasn't opened try and create a new one.
   // OR, if the file has no content.
   if ( ! m_fCrashstatus->is_open( ) || m_fCrashstatus->eof( ) ) {
	  // If we're just eof, close the file now...
	  if ( m_fCrashstatus->is_open( ) )
		 m_fCrashstatus->close( );

	  // Re-open the file for writing
	  m_fCrashstatus->open( szPath, std::ios.out | std::ios.binary );

	  // If it didn't open just get off here
	  if ( ! m_fCrashstatus->is_open( ) ) {
		 delete m_fCrashstatus;  // Clean up used memory
		 return false;
	  }

	  // Write a 1 into the stream so we assume the server
	  // exited cleanly last time.
	  m_fCrashstatus->write( "Test!\n", 7 );

	  // Close the file now
	  m_fCrashstatus->close( );
   }

   // If the file was opened earlier, we have to close it now
   // to re-open it in write mode.
   if ( m_fCrashstatus->is_open( ) )
	  m_fCrashstatus->close( );

   // Success!
   return true;
}
  
Reply With Quote