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

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

        <tfoot id='mKHgi'></tfoot>
      1. <small id='mKHgi'></small><noframes id='mKHgi'>

        如何组合输出流,以便输出一次到达多个位置?

        How can I compose output streams, so output goes multiple places at once?(如何组合输出流,以便输出一次到达多个位置?)
          <bdo id='jtRRZ'></bdo><ul id='jtRRZ'></ul>
            <legend id='jtRRZ'><style id='jtRRZ'><dir id='jtRRZ'><q id='jtRRZ'></q></dir></style></legend><tfoot id='jtRRZ'></tfoot>
              <tbody id='jtRRZ'></tbody>

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

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

                  本文介绍了如何组合输出流,以便输出一次到达多个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将两个(或更多)流合二为一.我的目标是将指向 coutcerrclog 的任何输出与原始流一起输出到文件中.(例如,当事情被记录到控制台时.关闭后,我希望仍然能够返回并查看输出.)

                  I'd like to compose two (or more) streams into one. My goal is that any output directed to cout, cerr, and clog also be outputted into a file, along with the original stream. (For when things are logged to the console, for example. After closing, I'd like to still be able to go back and view the output.)

                  我正在考虑做这样的事情:

                  I was thinking of doing something like this:

                  class stream_compose : public streambuf, private boost::noncopyable
                  {
                  public:
                      // take two streams, save them in stream_holder,
                      // this set their buffers to `this`.
                      stream_compose;
                  
                      // implement the streambuf interface, routing to both
                      // ...
                  
                  private:
                      // saves the streambuf of an ios class,
                      // upon destruction restores it, provides
                      // accessor to saved stream
                      class stream_holder;
                  
                      stream_holder mStreamA;
                      stream_holder mStreamB;
                  };
                  

                  这似乎很直接.然后 main 中的调用将类似于:

                  Which seems straight-forward enough. The call in main then would be something like:

                  // anything that goes to cout goes to both cout and the file
                  stream_compose coutToFile(std::cout, theFile);
                  // and so on
                  

                  我还查看了 boost::iostreams,但没有看到任何相关内容.

                  I also looked at boost::iostreams, but didn't see anything related.

                  还有其他更好/更简单的方法来实现这一目标吗?

                  Are there any other better/simpler ways to accomplish this?

                  推荐答案

                  你提到在 Boost.IOStreams 中没有找到任何东西.您是否考虑过 tee_device?

                  You mention having not found anything in Boost.IOStreams. Did you consider tee_device?

                  这篇关于如何组合输出流,以便输出一次到达多个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)
                    <bdo id='7H0qi'></bdo><ul id='7H0qi'></ul>
                  • <small id='7H0qi'></small><noframes id='7H0qi'>

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

                            <legend id='7H0qi'><style id='7H0qi'><dir id='7H0qi'><q id='7H0qi'></q></dir></style></legend>