• <small id='oDDTX'></small><noframes id='oDDTX'>

    <i id='oDDTX'><tr id='oDDTX'><dt id='oDDTX'><q id='oDDTX'><span id='oDDTX'><b id='oDDTX'><form id='oDDTX'><ins id='oDDTX'></ins><ul id='oDDTX'></ul><sub id='oDDTX'></sub></form><legend id='oDDTX'></legend><bdo id='oDDTX'><pre id='oDDTX'><center id='oDDTX'></center></pre></bdo></b><th id='oDDTX'></th></span></q></dt></tr></i><div id='oDDTX'><tfoot id='oDDTX'></tfoot><dl id='oDDTX'><fieldset id='oDDTX'></fieldset></dl></div>

  • <legend id='oDDTX'><style id='oDDTX'><dir id='oDDTX'><q id='oDDTX'></q></dir></style></legend>
    • <bdo id='oDDTX'></bdo><ul id='oDDTX'></ul>

      1. <tfoot id='oDDTX'></tfoot>

        使用 boost::iostreams::tee_device?

        时间:2024-08-14
      2. <i id='LZxS9'><tr id='LZxS9'><dt id='LZxS9'><q id='LZxS9'><span id='LZxS9'><b id='LZxS9'><form id='LZxS9'><ins id='LZxS9'></ins><ul id='LZxS9'></ul><sub id='LZxS9'></sub></form><legend id='LZxS9'></legend><bdo id='LZxS9'><pre id='LZxS9'><center id='LZxS9'></center></pre></bdo></b><th id='LZxS9'></th></span></q></dt></tr></i><div id='LZxS9'><tfoot id='LZxS9'></tfoot><dl id='LZxS9'><fieldset id='LZxS9'></fieldset></dl></div>

          <tfoot id='LZxS9'></tfoot>

          <small id='LZxS9'></small><noframes id='LZxS9'>

          • <bdo id='LZxS9'></bdo><ul id='LZxS9'></ul>
            <legend id='LZxS9'><style id='LZxS9'><dir id='LZxS9'><q id='LZxS9'></q></dir></style></legend>

                <tbody id='LZxS9'></tbody>
                • 本文介绍了使用 boost::iostreams::tee_device?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有人可以帮我吗?

                  我正在尝试执行以下操作:

                  I am trying to do something like the following:

                  #include <boost/iostreams/tee.hpp>
                  #include <boost/iostreams/stream.hpp>
                  #include <sstream>  
                  #include <cassert>  
                  
                  namespace io = boost::iostreams;
                  typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee;
                  std::stringstream ss1, ss2;
                  Tee my_split(ss1, ss2); // redirects to both streams
                  my_split << "Testing";
                  assert(ss1.str() == "Testing" && ss1.str() == ss2.str());
                  

                  但它不会在 VC9 中编译:

                  But it won't compile in VC9:

                  c:liboost_current_versionoostiostreamsstream.hpp(131) : error C2665: 'boost::iostreams::tee_device<Sink1,Sink2>::tee_device' : none of the 2 overloads could convert all the argument types
                  

                  有人用过这个吗?我知道我可以让自己的班级来做这件事,但我想知道我做错了什么.

                  Has anyone gotten this to work? I know I could make my own class to do it, but I want to know what I am doing wrong.

                  谢谢

                  推荐答案

                  您使用 constructor-forwarding version 的 io::stream,它自己构造一个 tee-stream 并将所有参数转发给它.C++03 在将参数转发给函数时只有有限的能力(需要的重载量很容易呈指数增长).它 (io::stream) 做了以下限制:

                  You use the constructor-forwarding version of io::stream, which construct a tee-stream itself and forward all arguments to that. C++03 has only limited capabilities when it comes to forwarding arguments to functions (amount of overloads needed easily grow exponentially). It (io::stream) makes the following restrictions:

                  这些成员中的每一个都构造了一个流的实例,并将其与从给定的参数列表构造的 Device T 的一个实例相关联.所涉及的 T 构造函数必须按值或常量引用获取所有参数.

                  Each of these members constructs an instance of stream and associates it with an instance of the Device T constructed from the given lists of arguments. The T constructors involved must take all arguments by value or const reference.

                  好吧,但是 tee_device 构造函数说

                  Well, but the tee_device constructor says

                  基于给定的一对接收器构造 tee_device 的实例.如果相应的模板参数是流或流缓冲区类型,则每个函数参数都是非常量引用,否则为常量引用.

                  Constructs an instance of tee_device based on the given pair of Sinks. Each function parameter is a non-const reference if the corresponding template argument is a stream or stream buffer type, and a const reference otherwise.

                  这当然行不通.io::stream 提供了另一个以 T 作为第一个参数的构造函数.这在这里有效(至少编译.不过,断言失败.我没有使用过 boost::iostreams,所以我无能为力)

                  That won't work, of course. io::stream provides another constructor that takes a T as first argument. This works here (Compiles, at least. The assertion fails, though. I've not worked with boost::iostreams so i can't help with that)

                  namespace io = boost::iostreams;
                  typedef io::tee_device<std::stringstream, std::stringstream> TeeDevice;
                  typedef io::stream< TeeDevice > TeeStream;
                  std::stringstream ss1, ss2;
                  TeeDevice my_tee(ss1, ss2); 
                  TeeStream my_split(my_tee);
                  my_split << "Testing";
                  assert(ss1.str() == "Testing" && ss1.str() == ss2.str());
                  

                  在调用 flush() 或流式传输 <<<;std::flush,断言通过.

                  After calling flush() or streaming << std::flush, the assertion passes.

                  这篇关于使用 boost::iostreams::tee_device?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C++ 从文件流中读取无符号字符 下一篇:自定义流到 C++ 中的方法?

                  相关文章

                  <legend id='IuP22'><style id='IuP22'><dir id='IuP22'><q id='IuP22'></q></dir></style></legend>

                  <tfoot id='IuP22'></tfoot>

                • <i id='IuP22'><tr id='IuP22'><dt id='IuP22'><q id='IuP22'><span id='IuP22'><b id='IuP22'><form id='IuP22'><ins id='IuP22'></ins><ul id='IuP22'></ul><sub id='IuP22'></sub></form><legend id='IuP22'></legend><bdo id='IuP22'><pre id='IuP22'><center id='IuP22'></center></pre></bdo></b><th id='IuP22'></th></span></q></dt></tr></i><div id='IuP22'><tfoot id='IuP22'></tfoot><dl id='IuP22'><fieldset id='IuP22'></fieldset></dl></div>

                    1. <small id='IuP22'></small><noframes id='IuP22'>

                        <bdo id='IuP22'></bdo><ul id='IuP22'></ul>