<p>I'm trying to code opposite action to this:</p>

<pre><code>std::ostream outs; // properly initialized of course
std::set&lt;int&gt; my_set; // ditto

outs &lt;&lt; my_set.size();
std::copy( my_set.begin(), my_set.end(), std::ostream_iterator&lt;int&gt;( outs ) );
</code></pre>

<p>it should be something like this:</p>

<pre><code>std::istream ins;

std::set&lt;int&gt;::size_type size;
ins &gt;&gt; size;

std::copy( std::istream_iterator&lt;int&gt;( ins ), std::istream_iterator&lt;int&gt;( ins ) ???, std::inserter( my_set, my_set.end() ) );
</code></pre>

<p>But I'm stuck with the 'end' iterator -- input interators can't use std::advance and neither I can use two streams with the same source...</p>

<p>Is there any elegant way how to solve this? Of course I can use for loop, but maybe there's something nicer :)</p>

(Edited: I should have read the question closer...)
While somewhat suspect, you can get approximately the right behavior by having an entry in the file that will "fail" the first loop, then clear the fail bit on the stream and start reading more.
Data, without an explicit size, but like this
```
1 1 2 3 5 8 Fibb
```
Fed to the code below seems to do what I meant, at least on VS2005 with STLPort.
```
typedef std::istream_iterator < int, char, std::char_traits ,ptrdiff_t> is_iter;
std::copy( is_iter(cin), is_iter(), inserter(my_set,my_set.end()));
cin.clear();
std::cin >> instr;
```