From: Atry (pop.atry_at_[hidden])
Date: 2007-05-03 01:20:40
Edwin Vane åé:
> I'd like to create an iostream that writes data in binary format to a
> pre-allocated block of memory. I'm already using array_sink to handle
> the 'write to a pre-allocated block of memory' part:
> char* my_data = new char;
> io::stream_buffer<io::array_sink> buf(my_data,1024);
> std::ostream os(&buf);
> int i = 15;
> float f = 5.1345;
> os << i;
> os << f;
> os << "Hello World!";
> os << 'c';
> However, all the data written to my_data is in text format (i.e. 15 is
> encoded in 2 bytes 0x31 0x35 instead of 4 (assuming 32-bit integers)).
> What I'd like is something like file_sink where you specify the mode as
> binary. The 'mode' seems to be a Device-level decision (as it is with
> basic_file_sink) so I'm guessing array_sink is not what I need afterall.
> Does something exist for writing binary data to a block of memory?
Please use Boost.Serialize.