c++stringvectoristringstream

How to initialise a stringstream from a vector char


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_?


Solution

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

    istringstream iss(string(v.begin(), v.end()));