I have figured out what's happening.
When you use std::getline() to read some text and then put it in a std::stringstream to process it with a while loop, you read exactly one line of text (up until the enter key) and then stop reading input.
When you use while(std::cin>>x) or use std::copy with a std::input_iterator it extracts information from std::cin until it gets to something it can't parse or until it gets to the end of the input - it skips ALL whitespace (including the enter key)
In this case we are reading int values so the std::getline()/std::stringstream/while method gets exactly one line of text and then the while contines extracting ints until the end of the input - in this case it's the end of the string we read.
But when using while(std::cin>>x) or std::copy what exactly indicates the end of the input? It isn't the enter key because that is whitespace. If you were redirecting the input from a file it would be the end of the file. But interactively, how do you make the end of the input from the keyboard?
- In a Unix shell you press the Ctrl-D key
- On Windows you press the Ctrl-Z key as the first character of a new line
Here's some more info:
The reason my samples worked on rextester.com is that you enter the input into a little box so it must be redirected in as a file - it isn't really interactive.