Query std::ostringstream content
<p>Is it possible to search the content of a <code>std::ostringstream</code> without using the <code>std::ostringstream::str()</code> member function to create a <code>std::string</code> to search?</p>

<p>I have the following and want to avoid constructing a <code>std::string</code> instance on every invocation of <code>flush_()</code>:</p>

<pre><code>#include &lt;iostream&gt;
using std::cout;

#include &lt;ios&gt;
using std::boolalpha;

#include &lt;sstream&gt;
using std::ostringstream;

#include &lt;string&gt;
using std::string;

class line_decorating_ostream
{
public:
    line_decorating_ostream()  { out_ &lt;&lt; boolalpha;  }
    ~line_decorating_ostream() { cout &lt;&lt; out_.str(); }

    template &lt;typename T&gt;
    line_decorating_ostream&amp; operator&lt;&lt;(const T&amp; a_t)
    {
        out_ &lt;&lt; a_t;
        flush_();
        return *this;
    }

private:
    ostringstream out_;
    line_decorating_ostream(const line_decorating_ostream&amp;);
    line_decorating_ostream&amp; operator=(const line_decorating_ostream&amp;);

    // Write any full lines.
    void flush_()
    {
        string s(out_.str());
        size_t pos = s.find('\n');
        if (string::npos != pos)
        {
            do
            {
                cout &lt;&lt; "line: [" &lt;&lt; s.substr(0, pos) &lt;&lt; "]\n";
                s = s.substr(pos + 1);

            } while (string::npos != (pos = s.find('\n')));

            out_.clear();
            out_.str("");
            out_ &lt;&lt; boolalpha &lt;&lt; s;
        }
    }
};

int main()
{
    line_decorating_ostream logger;

    logger &lt;&lt; "1 " &lt;&lt; "2 " &lt;&lt; 3 &lt;&lt; " 4 " &lt;&lt; 5 &lt;&lt; "\n"
           &lt;&lt; "6 7 8 9 10\n...\n" &lt;&lt; true &lt;&lt; "\n";

    return 0;
}
</code></pre>

<p>[<em>It is not causing any performance issues that I am concerned about, just curious if this is possible.</em>]</p>
