title: Problem with re-using a stringstream object
body: <p>I'm trying to use safe practices in handling input with numbers only in C++, so I use a stringstream object as so:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  int main()
  {
      int first, second;
      string input;
  
      stringstream sstream;
  
      cout &lt;&lt; "First integer: ";
      getline(cin, input);
      sstream.str(input);
      sstream &gt;&gt; first;
  
      cout &lt;&lt; first &lt;&lt; endl; //display user input in integers
  
      cout &lt;&lt; "Second integer: ";
      getline(cin, input);
      sstream.str(input);
      sstream &gt;&gt; second;
  
      cout &lt;&lt; second &lt;&lt; endl; //display user input in integers
  
      getline(cin, input); //pause program
  
      return 0;
  }
  </code></pre>
  
  <p>However, the second time around it seems to give the variable 'second' an arbitrary value. This is the output:</p>
  
  <pre><code>First integer: 1
  1
  Second integer: 2
  2293592
  </code></pre>
  
  <p>If I declare two stringstream objects and use them respectively for both variables it seems to work fine. Does this mean that I cannot re-use a stringstream object in the way I'm trying to do? In my real program I intend to handle much more than two input values from the user, so I just want to make sure if there's another way instead of making multiple stringstream objects. I doubt it's of great relevance but I'm on Windows XP and I'm using MinGW as my compiler.</p>
  
  <p>I greatly appreciate any help.</p>