5

currently I am using a boost char array

boost::array<char, 512> received_data;
std::istringstream ss_(received_data.data()); 

but what if my received_data was a std::vector<char> received_data(512);

how would I then get this data to my std::istringstream ss_?

  • There is no easy (and *correct*) way to do this properly. To do it right you either have to use boost or implement your own `streambuf` (which isn't *too* hard). – Timmmm Aug 07 '19 at 16:11
  • Possible duplicate of [C++: Wrapping vector with istream](https://stackoverflow.com/questions/8815164/c-wrapping-vectorchar-with-istream) – Timmmm Aug 07 '19 at 16:11

2 Answers2

6

The istringstream takes a string, and a string can be made from two char iterators, like this:

istringstream iss(string(v.begin(), v.end()));
benathon
  • 7,455
  • 2
  • 41
  • 70
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
2
std::vector<char> receivedData(512);

std::istringstream iss(&receivedData[0]);
Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66