title: stringstream duplicates last word
body: <p>I'm trying to split a string using stringstream : </p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main(){
      ifstream fp;
      string name;
  
      fp.open("in.txt");
      while (fp){
          string line;
          getline(fp, line);
          cout &lt;&lt; line &lt;&lt; endl;
          istringstream line_stream(line);
  
          while (line_stream){
              line_stream &gt;&gt; name;
              cout &lt;&lt; name &lt;&lt; " ";
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Here's in.txt : </p>
  
  <pre><code>cat bat rat sat
  </code></pre>
  
  <p>Here's the output I'm getting : </p>
  
  <pre><code>cat bat rat sat
  cat bat rat sat sat
  </code></pre>
  
  <p>The line retrieved from <code>getline()</code> function is right, but in the process of splitting I'm getting the last word twice. I'm not sure why is this happening.</p>