Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all

Does anyone tried ofstream on debugging ? In my case when it passes the write statement nothing is written on the file but on the normal run it writes to the file normally. I have a bug I need to check in the log file but through debugging. Thanks for the help! :)
Posted
Comments
Jochen Arndt 7-Jul-14 10:21am    
Do you stop execution at a break point?
Then the data might have not been written to disk yet.
Then call ofstream::flush() before the break point.
Sergey Alexandrovich Kryukov 7-Jul-14 11:12am    
Is the question if anyone tried? The answer is yes, of course. Many did it; if it was a problem, who would need the debugger? We cannot read your mind, and my access to your hard drive, due to hot weather, is a bit limited...
—SA
Abdallah Al-Dalleh 8-Jul-14 2:38am    
Jochen
Yes I stop at break points and once it passes the write statement nothing is written to the file!, I'll check the ofstream::flush() thanks!

Sergey
Man I'm having a bug I think debugging the ofstream might help in my case, If you have anything useful regarding my case that would be great!

1 solution

All stream-related writing operations are buffered. I. e. whenever you write something, the data will only be written to an internal buffer, which may or may not then be flushed to the output stream. You can force the write by flushing or closing the stream. See http://www.cplusplus.com/reference/ostream/ostream/flush/[^]
 
Share this answer
 
Comments
Abdallah Al-Dalleh 8-Jul-14 7:41am    
This didn't work, nothing is written to the file while debugging.
Stefan_Lang 9-Jul-14 2:27am    
Can you elaborate on "while debugging"? Did you check after a call to ofstream::flush()?

I'm not sure, but this may be an issue of the file system which won't let you see the current contents of the file until it's properly closed...
Albert Holguin 9-Jul-14 9:59am    
I've done this before... for debugging purposes... as long as you flush the buffer, it should write out to file. It's possible that somewhere in your code the output file name is different when in debug mode, check for that? Your path may also be different when running in debug mode, so make sure you're checking the right path.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900