Never use gets(), this dangerous C function can never be used safely. Since your using C++ prefer using C++ streams instead.
Since you're using such an old pre-standard compiler I don't recommend re-using streams unless you make sure you clear the error flags between re-use. Before the C++11 standard just closing and opening streams didn't clear() the stream error flags.
You really really should consider getting a newer standard compliant compiler and abandon your current compiler.