Buffer not flushing to disk

This is a discussion on Buffer not flushing to disk within the Game Programming forums, part of the General Programming Boards category; Problem: This log system does not flush the buffer on a premature exit (due to an error) from the program. ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598

    Buffer not flushing to disk

    Problem: This log system does not flush the buffer on a premature exit (due to an error) from the program.

    Code as follows:

    Header
    Code:
    #ifndef _LOGFILE_
    #define _LOFGILE_
    #include <iostream.h>
    #include <fstream.h>
    
    struct debugLog
    {	
      ofstream OutFile;
      void Open(char *txt);
      void Write(char *txt);
      void Close(void);
    };
    
    #endif
    Module
    Code:
    #include "logfile.h"
    
    void debugLog::Open(char *filename)
    {
      OutFile.open(filename,ios::out);
    }
    
    void debugLog::Write(char *text)
    {
      OutFile<<text;
    }
    
    void debugLog::Close(void)
    {
      OutFile.close();
    }

    Any suggestions??

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    void debugLog::Open(char *filename)
    {
      OutFile.open(filename,ios::out);
    }
    Are you sure it doesn't close the file when it reaches the closing brace?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Yeah it writes to the disk - just on errors it returns and exits before it writes the text completely to the disk.

    File handles remain open until closed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flushing buffer
    By $l4xklynx in forum C Programming
    Replies: 6
    Last Post: 03-04-2009, 10:07 PM
  2. Need help flushing buffer
    By MSF1981 in forum C Programming
    Replies: 2
    Last Post: 02-15-2009, 07:30 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 09:20 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21