title: Iterating over int and string with istream_iterator
body: <p>I am going through The C++ Programming Language Book and reached "Iterators and I/O" page 61 they give the following example to demonstrate iterating through a string submitted.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
  
      istream_iterator&lt;string&gt;ii(cin);
      istream_iterator&lt;string&gt;eos;
  
      string s1 = *ii;
      ++ii;
      string s2 = *ii;
  
      cout &lt;&lt;s1 &lt;&lt; ' '&lt;&lt; s2 &lt;&lt;'\n';
  }
  </code></pre>
  
  <p>Which I totally understand, now I was playing around with this example to make it work for numbers as well. I tried adding in the following in the respective places...</p>
  
  <pre><code>istream_iterator&lt;int&gt;jj(cin);
  int i1 = *jj;
  cout &lt;&lt;s1 &lt;&lt; ''&lt;&lt; s2 &lt;&lt; ''&lt;&lt; i1 &lt;&lt;'\n';
  </code></pre>
  
  <p>Which does not give me the chance to input the number section when running the program. Why is this so ? Can the iterator only be used once on <code>cin</code> ? such that it is already has input from <code>cin</code> so the next iterator is ignored ?</p>
  
  <hr>
  
  <p>Edit here is what I have after insertions</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
  
      istream_iterator&lt;string&gt;ii(cin);
      istream_iterator&lt;string&gt;eos;
  
      //istream_iterator&lt;int&gt;dd(cin);
  
      string s1 = *ii;
      ++ii;
      string s2 = *ii;
      //int d = *dd;
      int d =24;
      cout &lt;&lt;s1 &lt;&lt; ' '&lt;&lt;s2&lt;&lt;' '&lt;&lt;d&lt;&lt; '\n';
  }
  </code></pre>
  
  <p>The above works for </p>
  
  <p>Hello World
  <em>or</em><br>
  Hello<br>
  World  </p>
  
  <p>Giving Hello World as the output.</p>
  
  <p>removing the comments from</p>
  
  <pre><code>istream_iterator&lt;int&gt;dd(cin);
  int d = *dd;
  </code></pre>
  
  <p>and commenting out</p>
  
  <pre><code>int d =24;
  </code></pre>
  
  <p>Leads to Hello Hello 0 as the output.</p>