Ok, That was the simple theory.
Now things get more interesting. There are various things that can cause the status of a file to change. There are various flags you can test, including
You will need to check the status after each action. Firstly, was the file opened successfully? So check good() immediately after opening. If necessary, print out a suitable error message.
We'll assume the file opened correctly. Now what happens when the password is read? If the file is empty, the file will enter an error state. You can clear this by using
before attempting to write out the new password.
In the case of the diary.txt file, there may be the eof() (end of file) or fail() conditions to handle. You may also want set the file to write new text to the end, by using
See the reference section for more details,