Application uses RapidXML to edit XML file. Editing is not automated and takes place occasionally: XML content is displayed in GUI and user performs some actions which change XML. Each change must be saved to disk immediately.
Loading RapidXML document object requires copying the content of the file into a string. Each change in a document is followed by copying the content of the document object back into the file.
File is used both for input and output in this example. Shall a single std::fstream
object be used for all input/output operations in this case? It would be opened once, at the application startup, used for input/output, and closed at the end of the application.
Or, shall local (temporary) instances of std::ifstream
and std::ofstream
be used whenever file input/output needs to be performed? E.g. std::ifstream
to be used at the beginning for reading the file (open, read, close); similarly, std::ofstream
instance to be used whenever DOM must be exported into the file (open, write, close).
I am not concerned about performances here (due to the nature of the application) but am curious about the proper choice of file stream objects in this case.