将向量< unsigned char>里面流? [英] Wraps a vector<unsigned char> inside a stream?

查看:100
本文介绍了将向量< unsigned char>里面流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数作为参数std :: istream&并将变换后的流写入std :: ostream&。

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 ?

谢谢

2函数签名:

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

调用者将如下所示:

std::vector<unsigned char> data;
std::istrstream stream_in("input message");
std::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);

这篇关于将向量&lt; unsigned char&gt;里面流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆