55

c – 方便地将std :: vector复制到输入流(std :: istream)对象

 5 years ago
source link: https://codeday.me/bug/20190112/518588.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

我正在尝试使用第三方库中的函数,并期望输入流对象,其中传输二进制文件数据.

签名看起来像这样:

doSomething(const std::string& ...,
          const std::string& ...,
          std::istream& aData,
          const std::string& ...,
          const std::map<std::string, std::string>* ...,
          long ...,
          bool ...);

由于我无法更改/更改此第三方库/功能,因此我必须适应“我的”代码.在调用的地方,我有一个std :: vector,它包含了预期在istream对象中传递的数据.目前,我将矢量复制到流中,通过迭代并使用< JR 运算符逐字节复制>

vector<unsigned char> values;
// ...

stringstream ioss;    
copy(values.begin(), values.end(),
     ostream_iterator<unsigned char>(ioss,","));

// doSomething(a, b, ioss, d, e, f, g);

翻译自:https://stackoverflow.com/questions/9358255/conveniently-copy-stdvectorunsigned-char-to-input-stream-stdistream-obje


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK