为什么 istream_iterator抛出 std::bad_cast?
到底是怎么回事?
#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),但无济于事。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它从哨兵对象的构造函数中抛出,在该构造函数中检查流上的 ctype 方面(它需要它,以便可以跳过空格),它恰好是 NULL,因为它没有为无符号字符定义。
您需要处理该流上的空白吗?如果没有,则更改为
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
不应该是:
shouldnt it be: