c++ - Boost Iostreams component() 调用失败
问题描述
我正在尝试访问std::ifstream
添加到boost::iostreams::filtering_streambuf
链中的底层。根据常见问题解答,一种方法是使用component/component_type
. 为什么下面的代码会失败?
std::ifstream fp{"input.txt", std::ios_base::in | std::ios_base::binary};
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::counter{});
in.push(fp);
auto *c = in.component<boost::iostreams::counter>(0); // works
std::cout << (c == nullptr) << std::endl; // 0
std::cout << c->characters() << std::endl;
std::cout << c->lines() << std::endl;
// Look into ifstream
auto *f_ptr = in.component<std::ifstream>(1); // fails
std::cout << (f_ptr == nullptr) << std::endl; // 1
解决方案
推荐阅读
- python - 当我在我的在线服务器上运行一个函数时,我收到了一个错误(502 bad gateway)。在我的本地服务器上运行时我没有得到同样的错误
- couchbase - N1QL 选择数字键
- twitter - Flink Twitter 连接器 - 如何避免超出速率限制 (420)
- javascript - amp-form post action-xhr 响应剥离图像标签
- python - 用于银行交易分类的 TensorFlow 实现
- java - 使用外部控制输入来选择类或代码(“不安全反射”)
- python - 将“on_start 数据”传递给 MyScreen 和 MyImage 需要 ScreenManager 中的屏幕名称
- json - 将 JSON 节点转换为要选择的列
- c# - 有没有办法检查数据库中是否存在文本文件中的数据?
- javascript - 参数在 RN typescript 中隐式具有任何类型