I'm currently dealing with a custom buffer class which in its inside carries around its data in a classic C-Array (unsigned char[]).
To get a more comfortable read/write access to that buffer I was looking for a way to construct an std::istream object which is directly connected to the POD content... aka the C-Array memory. The goal is to using all the std::stream formatters and the actual data "lorem ipsum" should be directly written to the buffer. So something like this:
std::istream QuirkyBuffer::getIStream() { return std::istream(this->ptr, this->size); }
QuirkyBuffer d;
auto is = d.getIStream();
"lorem ipsum" >> is;
Is it possible to do that?
You can use std::ostrstream
for this. It's deprecated, but given its usefulness, I can't imagine it going away anytime soon.
Otherwise, it's very simple to write your own omemstream
.