Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does exit() flush and close `ofstream` objects?

Tags:

c++

exit

exit(3) says that stdio streams are flushed and closed. But nothing tells about C++-specific ofstream objects.

Does the standard guarantee that ofstream objects are also flushed and closed properly, or do I have to somehow propagate exit condition to main() and do a return there to destroy all automatic ofstreams?

like image 248
Ruslan Avatar asked Jan 11 '23 14:01

Ruslan


1 Answers

std::exit() destroys objects with static storage duration (thereby flushing such ofstream objects). It does not destroy objects with automatic storage duration (leaving such ofstream objects unflushed).

Whether the ofstream is flushed depends on its storage duration.

like image 66
Oswald Avatar answered Jan 21 '23 14:01

Oswald