Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何让boost::iostream在与std::ios::binary相当的模式下运行?_C++_Iostream_Eof_Boost Iostreams - Fatal编程技术网

C++ 如何让boost::iostream在与std::ios::binary相当的模式下运行?

C++ 如何让boost::iostream在与std::ios::binary相当的模式下运行?,c++,iostream,eof,boost-iostreams,C++,Iostream,Eof,Boost Iostreams,关于boost::iostreams,我有以下问题。如果有人熟悉编写过滤器,我将非常感谢您的建议/帮助 我正在编写一对multichar过滤器,它与boost::iostream::filtering\u stream一起作为数据压缩器和解压缩器工作。 我从编写压缩器开始,从lz家族中学习了一些算法,现在正在开发一个解压器 简单地说,我的压缩器将数据拆分为数据包,这些数据包单独编码,然后刷新到我的文件中 当我必须从文件中恢复数据时(在编程术语中,接收读取(字节计数)请求),我必须读取完整的压缩块

关于
boost::iostreams
,我有以下问题。如果有人熟悉编写过滤器,我将非常感谢您的建议/帮助

我正在编写一对multichar过滤器,它与
boost::iostream::filtering\u stream
一起作为数据压缩器和解压缩器工作。 我从编写压缩器开始,从lz家族中学习了一些算法,现在正在开发一个解压器

简单地说,我的压缩器将数据拆分为数据包,这些数据包单独编码,然后刷新到我的文件中

当我必须从文件中恢复数据时(在编程术语中,接收
读取(字节计数)
请求),我必须读取完整的压缩块,对其进行缓冲,解压缩,然后给出请求的字节数。我已经实现了这个逻辑,但现在我正在努力解决以下问题:


打包数据时,输出文件中可能会出现任何符号。我在使用
boost::iostreams::read(..,size)
读取包含符号
(十六进制1A,字符26)
的文件时遇到问题

例如,如果我使用的是
std::ifstream
,我会设置
std::ios::binary
模式,然后可以简单地读取此符号

当实现一个使用
boost::iostream::read
例程读取字符序列的
boost::iostream
过滤器时,有没有实现相同的方法


这里有一些代码:

//压缩
// -----------
滤除干扰;
向外推(我的压缩机());
out.push(file_sink(“file.out”));
//将“file.in”压缩为“file.out”
std::ifstream流(“file.in”);

out将文件读取为二进制文件的简短回答:

打开文件流时指定
ios\u base::binary


一个可编译的测试用例总是能突破文本墙。我遇到了一个类似的问题:看起来不错。但是,我是否有任何选项,例如,仅当相应的设备处于
二进制
模式时,才强制我的
过滤器
工作?或者这无法检查?在“二进制模式设备”的情况下,您指的是什么?
   // Compression
   // -----------
   filtering_ostream out;
   out.push(my_compressor());
   out.push(file_sink("file.out"));

   // Compress the 'file.in' to 'file.out'
   std::ifstream stream("file.in");
   out << stream.rdbuf();


   // Decompression
   // -------------
   filtering_istream in;
   in.push(my_decompressor());
   in.push(file_source("file.out"));

   std::string res;
   while (in) {
      std::string t;

      // My decompressor wants to retrieve the full block from input (say, 4096 bytes)
      // but instead retrieves 150 bytes because meets '1A' char in the char sequence

      // That obviously happens because file should be read as a binary one, but
      // how do I state that?
      std::getline(in, t); // <--------- The error happens here

      res += t;
   }