Reading formatted input from an istream
<p>The problem below has been simplified from real requirements.</p>

<p>Consider the following program:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;string&gt;
#include &lt;set&gt;
#include &lt;algorithm&gt;

using namespace std;

typedef string T; // to simplify, always consider T as string

template&lt;typename input_iterator&gt;
void do_something(const input_iterator&amp; first, const input_iterator&amp; last) {
    const ostream_iterator&lt;T&gt; os(cout, "\n");
    const set&lt;T&gt; words(first, last);
    copy(words.begin(), words.end(), os);
}

int main(int argc, char** argv) {
    const istream_iterator&lt;T&gt; is(cin), eof;
    do_something(is, eof);
    return 0;
}
</code></pre>

<p>The program extracts all the words from an <code>istream</code> (<code>cin</code>) and does something with them. Each word is seperated by a white space by default. The logic behind the formatted extraction is inside the <code>istream_iterator</code>.</p>

<p>What I need to do now is to pass to <code>do_something()</code> two iterators so that the extracted words will be separated by a punctuation character instead of a white space (white spaces will be considered as "normal" characters). How would you do that in a "clean C++ way" (that is, with the minimum effort)?</p>
