I’ve created an ofstream and there is a point in which I need to check if it’s empty or has had things streamed into it.
Any ideas how I would go about doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
std::ofstreamfiles don’t support this directly. What you can do if this is an important requirement is to create a filtering stream buffer which internally usedstd::filebufbut also records if there was any output being done. This could look look as simple as this:You can initialize an
std::ostreamwith this and query the stream buffer as needed: