Q:

std::istream_iterator stops advancing

Why does the following program output 
1 2 3 4 4 4

and not
1 2 3 4 5 6

for each of the values provided?
#include <iostream>
#include <iterator>
#include <vector>
#include <string>
#include <sstream>

int main()
{

    std::vector<int> numbers;
    std::stringstream ss;
    ss << " 1 2";
    std::istream_iterator<int> start{ss},end;
    ss << " 3 4";
    numbers.push_back(*start++);
    numbers.push_back(*start++);
    numbers.push_back(*start++);
    ss << " 5 6";
    numbers.push_back(*start++);
    numbers.push_back(*start++);
    numbers.push_back(*start++);

    std::cout << "numbers read in:\n";
    for (auto number : numbers) {
        std::cout << number << " ";
    }
    std::cout << "\n";
}

A:

Its not iterator doing as you might have thought. It's ss that is invalidated after iterator progressing. Initialiy stringstream constains 1 2 3 4 and is in valid state. But is invalidated by the third iterator dereference, so next operation ss << " 5 6" fails. To fix this, clear flags of stringstream variable:
//...
ss.clear();
ss << " 5 6";
//...

Output:
numbers read in:
1 2 3 4 5 6

