For completeness: remove, ostream::close and the return statement are all unnecessary. The following code will perform exactly the same operation.
1 2 3 4 5
|
void Basic::AutoSave()
{
std::ofstream save("save.txt");
save << b.balance << std::endl;
}
|
1. As Texan40 and IWishIKnew said, by default an ofstream is opened for overwrite (you only have to do something if you want to append to the existing file.)
2. So removing the file is not necessary (you're getting the o/s to do work unnecessarily.)
3. And ofstream::close() is called by the ofstream destructor.
4. And return; is not needed (as there's nothing to return.)
OK, so all these issues are benign. But when coding you should be aiming for the minimal and complete solution.
Apart from anything else, I'm far too lazy to type unnecessary code! :-)
Andy
PS If I was going to add code to this function, it would be for error handling.