Reputation: 5220
What is going on?
#include <iostream>
#include <iterator>
#include <sstream>
int main() {
std::basic_stringbuf<unsigned char> buf;
std::basic_istream<unsigned char> stream(&buf);
// the next line throws std::bad_cast on g++ 4.4
std::istream_iterator<unsigned char, unsigned char> it(stream);
}
I've tried stream.write(some_array, sizeof(some_array)
before constructing the iterator, to no avail.
Thanks.
Upvotes: 2
Views: 1191
Reputation: 47408
It throws from sentry object's constructor where it checks the ctype facet on the stream (it needs it so it can skip whitespace), which happens to be NULL because it's not defined for unsigned chars.
Do you need to handle whitespace on that stream? If not, change to
std::istreambuf_iterator<unsigned char> it(stream);
Upvotes: 2