Boost logo

Boost Users :

Subject: Re: [Boost-users] boost replacement for std::ostringstream
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2012-09-07 17:09:03


2012/9/7 Chris Stankevitz <chrisstankevitz_at_[hidden]>:
> On Thu, Sep 6, 2012 at 11:17 PM, Szymon Gatner <szymon.gatner_at_[hidden]> wrote:
>> You could use filtering_ostream with underlying vector and reserve()
>> on that vector.
>
> Szymon,
>
> Thank you that is exactly what I did:
>
> #include <boost/iostreams/device/back_inserter.hpp>
> #include <boost/iostreams/filtering_stream.hpp>
> #include <string>
>
> std::string Result;
>
> Result.reserve(99999);
>
> boost::iostreams::filtering_ostream Stream(
> boost::iostreams::back_inserter(Result));
>
> Stream.write(pBuffer, 99999); // this part is more complicated in my
> real scenario

Ah, of course you used string directly.

May I ask tho: why are you using a stream to write a block of memory
to a string? Why not just directly copying it to a vector (or a
string)? If there are no filters attached to a filtering_stream then
you just add overhead/complexity without any benefit.

Cheers,
Simon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net