Redirecting cout stream

This is a discussion on Redirecting cout stream within the C++ Programming forums, part of the General Programming Boards category; Does anyone know of a way that I can redirect cout to a specific stream, such as a log file? ...

  1. #1
    Arrow Mk84
    Guest

    Redirecting cout stream

    Does anyone know of a way that I can redirect cout to a specific stream, such as a log file? Here's the problem: I'm using a 3rd party 3D graphics library (openscenegraph) that reports errors using cout/cerr. The program I'm writing is an Windows App based on MFC, and as such has no console support. I've tried creating a console class on my own, but that effort has basically bombed out - the examples I have insert a stream directly to the console class, not to cout.

    I would like to capture/redirect the cout stream so I can read the errors that the library produces (I really wish OSG would just throw exceptions or provide some sort of base class for error handling that I could use...). My program's error handling system uses exceptions (like a good C++ program should) and stores them in a queue for later printing; it would be easy to add support for streams, assuming I could redirect cout.

    Thanks,
    Ryan

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, it is possible.

    I assume you're using Windows, try this function:

    Code:
     
    BOOL SetStdHandle(
      DWORD nStdHandle,  // input, output, or error device
      HANDLE hHandle     // handle
    );
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout to printf problems
    By hallo007 in forum C++ Programming
    Replies: 9
    Last Post: 09-27-2006, 11:22 AM
  2. Stream function question
    By 3kgt in forum C++ Programming
    Replies: 1
    Last Post: 03-04-2003, 06:30 PM
  3. c++ string input
    By R.Stiltskin in forum C++ Programming
    Replies: 4
    Last Post: 02-22-2003, 04:25 PM
  4. I'm REALLY confused. Why isn't cout or cin working here?
    By niudago in forum C++ Programming
    Replies: 8
    Last Post: 02-15-2003, 05:53 PM
  5. FAQ cout
    By evilmonkey in forum FAQ Board
    Replies: 1
    Last Post: 10-07-2001, 12:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21