title: Reuse std::stringstream and std::istream_iterator in loop
body: <p>I have the following text file:</p>
  
  <pre><code>0 0 0 0 0 1 0 0 2 3 4 2 1 2 1
  0 0 0 0 2 7 5 4 5 7 5 4 3
  3 2 4 6 2 7 2 7 5 4 5 7 5 4 3
  3 2 4 6 2 7 2 7 5 4  5 4 3
  0 0 0 0 0 1 0 2 3 4 2 1 2 1
  0 0 0 0 0 1 0 0 2 3 4 2 1 2 1
  0 0 0 0 2 1 2 1
  3 2 4 6 2 7 2 7 5 4 5 7 5 4 3
  3 2 4 6 2 0 2 3 4 2 1 2 1
  0 0 0 0 0 1 0 0 2 3 4 2 1 2 1
  3 2 4 6 2 7 2 7 5 4 5 7 5 4 3
  </code></pre>
  
  <p>I can read it with the following program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  int main()
  {
      std::ifstream is("numbers.txt");
      std::string line;
      std::vector&lt;std::vector&lt;int&gt;&gt; numbers{};
      while (std::getline(is,line)) {
          std::stringstream ss{line};
          std::istream_iterator&lt;int&gt; start{ss},end;
          numbers.emplace_back(start,end);
          std::cout &lt;&lt; "Read " &lt;&lt; numbers.back().size() &lt;&lt; " numbers in row\n";
      }
      std::cout &lt;&lt; "Read " &lt;&lt; numbers.size() &lt;&lt; " rows\n";
  
      std::cout &lt;&lt; "numbers read in:\n";
      for (auto row : numbers) {
          for (auto number : row) {
              std::cout &lt;&lt; number &lt;&lt; " ";
          }
          std::cout &lt;&lt; "\n";
      }
      std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>I would like to create the <code>std::stringstream</code> and <code>std::istream_iterator</code> only once outside the loop. How could I adjust the iterator to the correct position each time the loop executes in the following program?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  int main()
  {
      std::ifstream is("numbers.txt");
      std::string line;
      std::vector&lt;std::vector&lt;int&gt;&gt; numbers{};
      std::stringstream ss{line};
      std::istream_iterator&lt;int&gt; start{ss},end;
      while (std::getline(is,line)) {
          ss &lt;&lt; line;
          //start = ss.beg;
          numbers.emplace_back(start,end);
          std::cout &lt;&lt; "Read " &lt;&lt; numbers.back().size() &lt;&lt; " numbers in row\n";
      }
      std::cout &lt;&lt; "Read " &lt;&lt; numbers.size() &lt;&lt; " rows\n";
  
      std::cout &lt;&lt; "numbers read in:\n";
      for (auto row : numbers) {
          for (auto number : row) {
              std::cout &lt;&lt; number &lt;&lt; " ";
          }
          std::cout &lt;&lt; "\n";
      }
      std::cout &lt;&lt; std::endl;
  }
  </code></pre>