Looks good to me except: The reason you are getting the last input twice is that you aren't testing for end of file after you read: You are testing it at the start of your loop. Add this code to see what I mean:
1 2 3 4 5 6
cerr << "I just read " << str;
cerr << ": EOF is " << boolalpha << cinInput.eof() << "." << endl << flush;
When you run your program, redirect stderr to a file like this: main 2>main.err