I have a file with saved data that sometimes needs to be received, written, erased, etc., when the program is running. I decided to write a SavedDataHandler class for this. I am currently using a class fstream.
I believed that one data element is the stream itself, opening it in the constructor and closing it in the destructor. However, I realized that the different functions called by SavedDataHandler open the stream in different ways (setting different flags, etc.), so I decided not to go along this route.
Instead, I only static const std::stringhave the file name, and the public member functions handle opening and closing the file as needed. Performance is not a problem.
Is this route valid? Since it does not have data elements, providing a constructor is not even required. It is just a class that contains functions (and one static constant), with functions running on the resource, not a data item.
source
share