这是怎么回事?
#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);
}
在构造迭代器之前,我尝试了 stream.write(some_array, sizeof(some_array)
,但无济于事。
谢谢。
最佳答案
它从 sentry 对象的构造函数中抛出,它检查流上的 ctype 面(它需要它以便它可以跳过空格),它恰好为 NULL,因为它没有为无符号字符定义。
您需要处理该流上的空格吗?如果不是,则更改为
std::istreambuf_iterator<unsigned char> it(stream);
关于c++ - 为什么 istream_iterator<unsigned char, unsigned char> 抛出 std::bad_cast?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3610000/