how can i create an istream from a buffer unsigned char* or vector.
basically i want :
void Func(vector<unsigned char> data)
{
someSortOfIstream x (data);
x >> something;
}
using boost too….
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would recommend:
use a
std::string(a fancy vector ofchars) instead of astd::vector<unsigned char>, because that’s what it’s for. You can then use the readily availablestd::stringstreamin the<sstream>header.You can subclass a
std::vector<unsigned char>and overload theoperator>>()for what you need it.OR
(harder but theoretically better) You can subclass
std::iostreamfor your case and tell it what to do when you useoperator>>()on itPersonnally I’d go with 1, and if you must, with 2a) because frankly, I’d have no idea how to subclass an
iostream.