title: How do I use the ostringstream properly in c++?
body: <p>I am attempting to return some information when my toString() method is called, which include an integer and some floats. I learned about ostringstream works great but when the class that contains this method is called over and over again, the information gets stacked onto my previous output. Here is my code</p>
  
  <pre><code>    ostringstream int_buffer, float_buffer, float_buffer2;
  </code></pre>
  
  <p>is introduced at the beginning of my class, then </p>
  
  <pre><code>    string toString()
      {
  
          int_buffer &lt;&lt; on_hand;
          float_buffer &lt;&lt; price;
          float_buffer2 &lt;&lt; generated_revenue;
  
          string stron_hand = int_buffer.str();
          string strprice = float_buffer.str();
          string strrev = float_buffer2.str();
  
          string output = "Product name: " + description + " Units left: " + stron_hand + " Price: " + strprice + " Revenue: $" + strrev;
          return output;
      }
  </code></pre>
  
  <p>I know my coding is awful, I'm still fairly new to this, but an example of my output is,</p>
  
  <p><i><b>"Product name: Movie Ticket Units left: 49 Price: 9.99 Revenue: $9.99"</p>
  
  <p>"Product name: Movie Ticket Units left: 4926 Price: 9.999.99 Revenue: $9.99239.76"</b></i></p>
  
  <p>where the second one should display</p>
  
  <p><i><b>"Product name: Movie Ticket Units left: 26 Price: 9.99 Revenue: $239.76"</b></i></p>
  
  <p>I know it's just a matter of updating, but that's where I'm lost.</p>