title: C++ Stringstream: Accepts a string, but not a string stored in a variable. Why?
body: <p>I've been trying to split up an input string into smaller strings delineated by whitespace. I found this code from <a href="https://stackoverflow.com/a/325042" title="here">here</a>:  </p>
  
  <pre><code>stringstream ss ("bla bla");
  string s;
  
  while (getline(ss, s, ' ')) {
  cout &lt;&lt; s &lt;&lt; endl;
  }
  </code></pre>
  
  <p>which works just fine. However, if I replace "bla bla" with a variable containing a string:</p>
  
  <pre><code>string userInput;
  cin &gt;&gt; userInput;
  
  stringstream ss (userInput);
  string s;
  
  while (getline(ss, s, ' ')) {
  cout &lt;&lt; s &lt;&lt; endl;
  }
  </code></pre>
  
  <p>only the first word/char/string prints out. Why is that? Is there a way to fix it? I've looked around at some stringstream questions, but the problem is that I don't really know what I'm looking for. </p>