Note that
ifstream::eof() only checks the
eofbit, i.e. it tells you whether a
previous read operation has failed
because of hitting the end of the file. But other errors are possible! In which case the
failbit or
badbit will be set instead of the
eofbit. So, it's probably better to check
ifstream::good() instead of
ifstream::eof(), because
ifstream::good() will only return
true, if
neither the
eofbit,
failbit or
badbit are set.
https://www.cplusplus.com/reference/ios/ios/good/
Also note that it is
not sufficient to check
ifstream::good() (or
ifstream::eof())
before calling
operator>>(). That is because even if there was
no error until now, the next read operation
may fail! So it's necessary to check the error bits
after each read operation in order to determine whether the read has succeeded.
This expression:
if ((!infile1.eof()) and (inFile1Written == true))
...can be simplified to just:
if ((!infile1.eof()) && inFile1Written)
And the expression:
if (inFile1Written == false)
...can be simplified to just:
if (!inFile1Written)