Thread: steambuf with multiple destinations

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    steambuf with multiple destinations

    My program uses cout for all of its output. Currently the user can specify a silent mode that points cout into a log file. I'd like to have an option where cout will print as usual and to a log file. Possible?

    Thanks.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not really. You could (possibly) inherit from ostream and create your own type, that outputs to both cout and a logfile, but generally it is probably better to make a function that replaces your regular cout operations.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Feared so. Thanks.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    Using the C output functions this is actually a rather easy task. Perhaps what you could do is see if you can simply redirect cout doing something similar. Your code would not likely be very portable but I betcha that you can whip up something.

  5. #5

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Ah excellent. I figured the solution went that way but never put the time into writing (learning) the streambuf. Thanks, codeplug.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. why Multiple define error ...
    By nilathinesh in forum C Programming
    Replies: 2
    Last Post: 10-19-2006, 06:31 AM
  3. Phantom redefinition
    By CodeMonkey in forum C++ Programming
    Replies: 6
    Last Post: 06-12-2005, 05:42 PM
  4. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM