while(fo)
else
fo.close(); //this does not set any fail flags
}
your loop goes one time too many. The last time nothing is wrote to the file (it is closed) but the 's' object does change.
Then you try to read, you are standing 'at the end' of the file, there is nothing there.
But it is not eof(), so the loop executes, however line 47 fails, it has no effect on 's', that maintains the last value.
I'm not sure of what is the rule for an invalid reading operation, I wouldn't expect the object to remain the same.
Not sure what error you are getting but as ne555 pointed towards; just because you closed fo doesn't make fo null.
ofstream will return null if it fails to init.