title: What exactly does stringstream do?
body: <p>I am trying to learn C++ since yesterday and I am using this document: <a href="http://www.cplusplus.com/files/tutorial.pdf" rel="nofollow noreferrer">http://www.cplusplus.com/files/tutorial.pdf</a> (page 32). I found a code in the document and I ran it. I tried inputting Rs 5.5 for price and an integer for quantity and the output was 0.
  I tried inputting 5.5 and 6 and the output was correct.</p>
  <pre><code>// stringstreams
  #include &lt;iostream&gt; 
  #include &lt;string&gt; 
  #include &lt;sstream&gt; 
  
  using namespace std; 
  
  int main () 
  { 
    string mystr; 
    float price = 0; 
    int quantity = 0; 
  
    cout &lt;&lt; &quot;Enter price: &quot;; 
    getline (cin,mystr); 
    stringstream(mystr) &gt;&gt; price; 
    cout &lt;&lt; &quot;Enter quantity: &quot;; 
    getline (cin,mystr); 
    stringstream(mystr) &gt;&gt; quantity; 
    cout &lt;&lt; &quot;Total price: &quot; &lt;&lt; price*quantity &lt;&lt; endl; 
    return 0; 
  }
  </code></pre>
  <p>What exactly does the mystring command do? Quoting from the document:</p>
  <blockquote>
  <p>&quot;In this example, we acquire numeric values from the standard input
  indirectly. Instead of extracting numeric values  directly from the
  standard input, we get lines from the standard input (cin) into a
  string object (mystr), and then  we extract the integer values from
  this string into a variable of type int (quantity).&quot;</p>
  </blockquote>
  <p>My impression was that the function will take an integral part of a string and use that as input.</p>