Buffer-based stringstream without copying

38 views Asked by At

Suppose I have two APIs that I need to interact with:

  • API 1 is a producer which provides me with a raw character buffer (const char*) and a length (say std::size_t).
  • API 2 is a consumer which expects an std::istream.

I'd like to use this buffer for a std::istringstream, but if I'm not mistaken, I'll have to turn the raw character buffer into a std::string first, copying its contents. I'd like to avoid that.

So my question is: Is there a way I could directly make an istringstream read from a buffer without copying the buffer using the stdlib, and without writing my own bufferstream class?

Is there a good reason for istringstreams being restricted to, well, strings - especially since using strings as buffers is considered bad practice?

0

There are 0 answers