Given a function that takes an output stringstream as an argument:
void Foo(const std::ostringstream& _oss);
Is there any way of writing the stream buffer to a file WITHOUT having to call str() ?
I want to avoid copying the buffer (which str() does).
void Foo(const std::ostringstream& _oss);
{
std::ofstream f("foo.bin");
//WANT: write _oss to f without copying the buffer?
}
There’s an
operator<<()taking a stream buffer:However, the buffer needs to be really big for this to make a noticeable difference. Usually, writing to disk will dominate the time needed for this anyway.
Note that I’d avoid creating identifiers with leading underscores.