The C++ code below does int to string and a string to int conversions. Then, it repeats these steps again. The stringst
int
string
stringst
The problem is that the stream's EOF flag is being set while extracting the integer (i.e. stream1.eof() returns true), but you never clear it. Inserting a call to stream1.clear() after extraction fixes your issue.
stream1.eof()
true
stream1.clear()