Jan 2, 2015

[C++] exit won't flush ostream object. Related to don't use exit in C++ code.

Does exit() flush and close `ofstream` objects?
RAII vs. exit()

quote:
exit should not flush iostreams.
iostreams are flushed on close() (on the stream types where it is available),
when flush is called explicitly on the stream, or on destruction.

Using exit in your application will leave objects in the state they are in (unless they are static), so resources requiring cleanup will be leaked.

This doesn't apply to memory leaks though, as most operating systems clean memory allocated for a program themselves, when the program exits.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.