gpt4 book ai didi

c++ - 为什么 istream_iterator 抛出 std::bad_cast?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:00:07 26 4
gpt4 key购买 nike

这是怎么回事?

#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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com