Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Implementing my own stream

Hello! My problem can be described the following way:

I have some data which actually is an array and could be represented as char* data with some size

I also have some legacy code (function) that takes some abstract std::istream object as a param and uses that stream to retrieve data to operate.

So, my question is the following - what would be the easy way to map my data to some std::istream object so that I can pass it to my function? I thought about creating a std::stringstream object from my data, but that means copying and (as I assume) isn't the best solution.

Any ideas how this could be done so that my std::istream operates on the data directly?

Thank you.

like image 650
Yippie-Ki-Yay Avatar asked Jun 06 '10 23:06

Yippie-Ki-Yay


1 Answers

If you're looking at actually creating your own stream, I'd look at the Boost.Iostreams library. It makes it easy to create your own stream objects.

like image 103
rlbond Avatar answered Sep 30 '22 07:09

rlbond