title: Splitting a string into integers using istringstream in C++
body: <p>I'm trying to use <code>istringstream</code> to split a simple string into a series of integers:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main(){
  
      string s = "1 2 3"; 
      istringstream iss(s);   
  
      while (iss)
      {
          int n;
          iss &gt;&gt; n;
          cout &lt;&lt; "* " &lt;&lt; n &lt;&lt; endl;
      } 
  }
  </code></pre>
  
  <p>And i get:</p>
  
  <pre><code>* 1
  * 2
  * 3
  * 3
  </code></pre>
  
  <p>Why is the last element always coming out twice? How to fix it?</p>