It doesn't directly test for the end of file. I don't know the type of your variables s, s1 and s2, so the behaviour might differ for say int or string types. But basically, if you do this:
file1 >> word;
the >> extraction operator will first read and ignore any leading whitespace. Then, if we assume it finds a letter such as 'A', it will add that, and any non-whitespace characters to the variable
1. a whitespace character is found, in which case it is left in the file buffer, or
2. the end of file is reached.
After this operation, if a value was successfully read into the variable, the
flag will be off. If it was not successful, the
flag is set on. As for the
flag, well it may or may not be set, depending upon whether there was any trailing whitespace after the data item.
We don't actually care whether the end-of-file flag was set or not. We are only interested in whether or not the input operation was successful.