Felics Felics - 3 months ago 74
C++ Question

How to redirect stdout to output window from visual studio

Is it possible to redirect stdout to output window from Visual Studio? I use in my program OutputDebugString but I use some libraries that have output debug messages with printf's or cout's.


Straightforward stdout redirection will not work, as there is no handle corresponding to OutputDebugString. However, there should be a way:

It could be done by redirecting the stdout to a pipe, then creating a thread which would read the pipe and print anything read from it using OutputDebugString.

Note: I was contemplating for a long ago to implement this, as I am facing exactly the same problem as you do (some libraries using printf or fprintf(stderr....), however I never really did this, I have always ended modifying the libraries instead, therefore I do not have a working implementation, but I think it should be feasible in principle.