title: When parsing a string using a string stream, it extracts a new line character
body: <p><strong>Description of the program :</strong> The program must read in a variable amount of words until a sentinel value is specified ("#" in this case).  It stores the words in a vector array.</p>
  
  <p><strong>Problem :</strong> I use a getline to read in the string and parse the string with a stringstream.  My problem is that the stringstream is not swallowing the new line character at the end of each line and is instead extracting it.</p>
  
  <p>Some solutions I have thought of is to cut off the last character by creating a subset or checking if the next extracted word is a new line character, but I feel there is a better cost efficient solution such as changing the conditions for my loops.</p>
  
  <p>I have included a minimized version of the overall code that reproduces the problem. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
     const int MAX_LIST_SIZE = 1000;
     string str;
     string list[MAX_LIST_SIZE];
     int numWords = 0;
  
     // program starts here
     getline(cin, str);          // read innput
     stringstream parse(str);    // use stringstream to parse input
  
     while(str != "#")           // read in until sentinel value
     {
         while(!parse.fail())    // until all words are extracted from the line    
         {
             parse &gt;&gt; list[numWords];    // store words
             numWords++;
         }
         getline(cin,str);      // get next line
         parse.clear();
         parse.str(str);
     }
  
     // print number of words
     cout &lt;&lt; "Number of words : " &lt;&lt; numWords &lt;&lt; endl;
  }
  </code></pre>
  
  <p>And a set of test input data that will produce the problem</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>apples oranges mangos
  bananas 
  pineapples strawberries
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Number of words : 9
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>Number of words : 6
  </code></pre>
  
  <p>I would appreciate any suggestions on how to deal with this problem in an efficient manner.</p>