I have std::stringstream ss;, containing binary data that I want to put into std::vector<unsigned char> my_vector;. Then, I want to take my_vector and use it to create a new std::stringstream new_ss identical to ss.
I have tried doing something similar to answers from this question:
Is there a more efficient way to set a std::vector from a stream?
and this question:
ending up with:
std::copy(std::istream_iterator<unsigned char>(ss),
          std::istream_iterator<unsigned char>(),
          std::back_inserter(my_vector));
then:
std::copy(my_vector.begin(), 
          my_vector.end(),
          std::ostream_iterator<unsigned char>(new_ss));
but ss and new_ss are not the same. I suspected that the problem might be something to do with ignored whitespace so I tried making the vector in this way instead:
    std::string const& s = ss.str();
    my_vector.reserve(s.size());
    my_vector.assign(s.begin(), s.end());
but this did not fix the problem.
Any ideas on what could be wrong or advice on a better way to solve this problem would be greatly appreciated.
 
     
     
    