Link to home
Start Free TrialLog in
Avatar of Beechy
Beechy

asked on

output to file using ofstream without closing stream.

Hi everyone,

Apologies for the newbie question, but I'm having problems with the ofstream object.

Basically I'm using it to create a log. I have a log object which when created opens the log file with the following command...

oFile.open ("ITSO Module.log", ofstream::out | ofstream::app, filebuf::sh_read);
oFile << "----------------------------------------------------------------\n";

I then call a writeLog(LPSTR lpMessage) command which outputs to the log like so....

oFile << lpMessage;

When the program exits the log object is destroyed and the following call made...

oFile.close()

The problem is that I can't see tha changes made to the log file until I close the app. How can I make it so the updates to the log file can be seen as they happen (i.e. without having to close the file)

Thanks in advance,

Beechy
ASKER CERTIFIED SOLUTION
Avatar of cup
cup

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cup
cup

Hoegie - you're right there.  I'd forgotten that endl does a flush.
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points split between cup and Hoegje

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (https://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer