title: How to read output from ostream?
body: <p>[SOLUTION]</p>
  
  <p>You can pass a stringstream into the paramater that takes an ostream. After that you can get the text that was set inside the stringstream by its str() funktion.</p>
  
  <pre><code>#include &lt;sstream&gt;
  
  ...
  
  {
  stringstream ss;
  print(ss);
  string text;
  text = ss.str();
  // Handle text
  }
  </code></pre>
  
  <p>Given there's a function like this:</p>
  
  <pre><code>void print(ostream&amp; stream) const;
  </code></pre>
  
  <p>How can I access the data that is written into the ostream?</p>
  
  <p>I was thinking of interpreting it as a string:</p>
  
  <pre><code>string text;
  print( text );
  // Interpret text
  </code></pre>
  
  <p>The reason is there's another function that has a pointer to an object as a parameter:</p>
  
  <pre><code>void append( *Data data );
  </code></pre>
  
  <p>And I must use the data objects print method to get at its data:</p>
  
  <pre><code>// This is a public function in the Data class
  void append( *Data data ) {
      string text;
      data-&gt;print( text );
      // append data to this Data object
  }
  </code></pre>
  
  <p>I was trying to cast to a stringstream but that didn't work. I'm thinking if I could save the data to a file and then read it as workaround.</p>