SDL: printf/cout ?

Started by
4 comments, last by bjarnia 16 years, 3 months ago
I just started playing with SDL, as I think GLUT is quite limiting. I however did like the console window that GLUT spawned, where I could print out debugging information. I'm perfecetly capable of placing breakpoints and such, but sometimes printing out to a console is a better and faster way. Is it possible to spawn such a window in SDL? Where do printf() lines go anyway? /dev/null? :o Ps.. I know that singleton file logging is pretty effective for debugging.. But I prefer console method for quick and dirty debugging... I use file logging as well for the more obvious stuff and error handling.
____________________________Bjarni Arnasonbjarni.us
Advertisement
How SDL handles stdout and stderr depends on the platform. For example, on Windows, if the application is compiled for the Windows subsystem, SDL redirects stdout and stderr to text files.
Don't use a singleton log file.

This code works for me:
#ifdef _WIN32	    const char * confile = "CONOUT$";        FreeConsole();    if(  !AllocConsole() )    {        // handle error    }        freopen(confile, "w", stdout);    freopen(confile, "w", stderr);#endif


However, this way you lose logging to files, which is handy. If you are feeling adventurous, you can write a custom std::streambuf that redirects printing to std::cout (or any stream) to an arbitrary location. With a bit of work, you can write a streambuf that writes to a console and to a file. However, you would have to switch from printf to C++ streams. Which is probably a good idea.
Ok.. In that case, I'll probably just log everything then..

However.. does anyone know of a good lightweight "log watching" program? that would function similarly to a console window.. I could just let it sit on my other monitor and instantly print out to a window anything that was written to the log?

EDIT:
The code above worked. Thanks a ton, that's awesome!

However.. Still, if anyone does happen to know of a log watching program that I described above, feel free to post :)
____________________________Bjarni Arnasonbjarni.us
How about this?

http://tailforwin32.sourceforge.net/

EDIT: Or just "tail -f". I assumed you were on Windows for some reason :)
Thanks. That was exactly what I was looking for.

Ps yes I am on windows... I've used tail before on linux but it didn't ring a bell this time, or else it would've been easier to google :)
____________________________Bjarni Arnasonbjarni.us

This topic is closed to new replies.

Advertisement