2

到底是怎么回事?

#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)在构建迭代器之前尝试过,但无济于事。

谢谢。

4

2 回答 2

2

它从哨兵对象的构造函数中抛出,在该构造函数中检查流上的 ctype 方面(它需要它以便它可以跳过空格),这恰好是 NULL,因为它没有为无符号字符定义。

您需要处理该流上的空格吗?如果没有,请更改为

std::istreambuf_iterator<unsigned char> it(stream);
于 2010-08-31T14:48:42.193 回答
0

不应该是:

std::istream_iterator<unsigned char> it(stream);
于 2010-08-31T14:40:49.597 回答