title: Save istream position for later use
body: <p>I wrote the code below which should save istream iterators. What I want is to keep the iterator for later copy to a string at the given position. This works fine until I reset the stream to the beginning. The output is "teet" bis I wanted "tees". Is there any way to make an iterator independent from the stream position?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;iterator&gt;
  
  int main(){
      std::stringstream test;
      test &lt;&lt; "test 123456\n";
  
      std::istream_iterator&lt;char&gt; it(test);
      std::cout &lt;&lt; *it;
      it++;
      std::cout &lt;&lt; *it;
  
      test.clear();
      test.seekg(0, std::ios::beg);
  
      std::cout &lt;&lt; *it;
      it++;
      std::cout &lt;&lt; *it;
  }
  </code></pre>