Re: How to redirect clog to cout and ofstream at the same time?

Discussion in 'C++' started by Jeff Flinn, Sep 11, 2010.

  1. Jeff Flinn

    Jeff Flinn Guest

    Francesco S. Carta wrote:
    > ksamdev <>, on 10/09/2010 06:15:50, wrote:
    >
    >> Hi,
    >>
    >> Is is possible to make clog output messages into two output stream
    >> simultaneously, say: cout and ostream?
    >>
    >> Unfortunately, ostream::rdbuf(...) allows to set only one at a time.
    >>
    >> I'd like to have messages that are sent to clog to be output on the
    >> screen and logged in file at the same time.

    >
    > Consider creating a stream-like "mylog" class and set it to output the
    > data to whatever you like, whenever you insert data into it. Obviously,
    > you should replace all occurrences of "clog" with "mylog", then.


    See boost::iostreams::tee_device at

    http://www.boost.org/doc/libs/1_44_0/libs/iostreams/doc/index.html

    Jeff
    Jeff Flinn, Sep 11, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Squid Seven

    ofstream * vs. ofstream

    Squid Seven, Jul 13, 2005, in forum: C++
    Replies:
    5
    Views:
    597
    Ivan Johansen
    Jul 14, 2005
  2. Joe Hesse

    Use cout as ofstream object

    Joe Hesse, Sep 26, 2007, in forum: C++
    Replies:
    5
    Views:
    486
    Salt_Peter
    Sep 26, 2007
  3. Replies:
    5
    Views:
    719
    Jim Langston
    Jan 13, 2009
  4. ksamdev
    Replies:
    3
    Views:
    409
    Stuart Redmann
    Sep 13, 2010
  5. ksamdev
    Replies:
    2
    Views:
    1,192
    ksamdev
    Sep 10, 2010
Loading...

Share This Page