I have a simple question. I have an ofstream to which I write data. After I am done and call close(), do I need to call delete on the handle or does close() perform cleanup?
For example:
mFileStream = new std::ofstream(LogPath.c_str(), std::ios::trunc);
...
mFileStream->Close();
//delete mFileStream?
My intuition is yes as I have allocated it, but I am not sure where I read it. Can anyone clarify?
Yes you have to. In C++ you must pair
newanddelete.Though, in a simple case like this you don’t need to, you can allocate your object on the stack and it will be destroyed for you, this is strongly recommended (faster and safer):
Small note: it is
closewith a small “c”.