Billy ONeal
Billy ONeal

Reputation: 106549

Does allowing a std::fstream to be destroyed close the associated file?

I'm wondering if I need an RAII wrapper around std::fstream....

Upvotes: 0

Views: 175

Answers (1)

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 507005

No you don't. It closes the file. § 27.8.1.2:

virtual ˜basic_filebuf();  

Effects: Destroys an object of class basic_filebuf. Calls close().

(which is contained as an object within std::fstream (§ 27.8.1.11), thus being destructed when the fstream is destructed).

Upvotes: 6

Related Questions