I want to wrap a vector<char> with std::istream (so reading the vector would be done through the istream interface)
What’s the way to do it?
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.
You’d define a
streambufsubclass wrapping thevector, and pass an instance of that to the istream constructor.If the data does not change after construction, it is sufficient to set up the data pointers using
streambuf::setg(); the default implementation for the other members does the right thing:If you need anything more advanced than that, override the
streambuf::underflowmethod.