The following code appends text to the end of tests.txt file as expected.
But when I uncomment the while loop (lines 27-30), nothing is appended to tests.txt.
Its as if getline() breaks fstream. Why is that?
Stick a testsFile.clear(); after the while loop.
See, after the while loop finishes, testsFile has an error flag set (most likely eofbit if it read through the end of the file), so then nothing else (?) will work as long as the stream is errored out like that.
So testsFile.clear(); will clear the error flags and let you keep using it normally.