开发者

Wraps a vector<unsigned char> inside a stream?

I have a function which takes as argument an std::istream& and writes a transformed stream to an std::ostream&.

On the another hand, I have another function which accepts a vector argument.

My goal is to pass the output of the first function to the second function.

Is there something out of the box to do that ? Otherwise, how can I easily implement it ?

Thank you

Edit : here are the 2 functions signature :

functionA(std::istream& _in, std::ostream& _out);
functionB(std::vector<unsigned char>& data);

The caller would look like :

std::vector<unsigned char> data;
std::istrstream stream_in("input message");
st开发者_运维百科d::ovectorstream stream_out(data); // ???
functionA(stream_in, stream_out);
functionB(stream_out.vector());


I think something like this might work

std::vector<unsigned char> data;
std::istringstream stream_in("input message");
std::stringstream stream_out;
functionA(stream_in, stream_out);
const std::string& str_out(stream_out.str());
copy(str_out.begin(), str_out.end(), std::back_inserter(data));
functionB(data);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜