Advertisement

cout to console in SDL

Started by February 07, 2005 04:57 AM
40 comments, last by fastcall22 13 years ago
I find it very hard using the debugger provided with Dev-C++ as I cannot make him stop where I want and check the value of every variable, so I would like to print them on the console of course, not on the actual SDL window, but on the dos prompt). It happens that cout doesn't work: is there a way to get cout working as always? Thank you all!
try to put these lines in your code

freopen( "CON", "wt", stdout );
freopen( "CON", "wt", stderr );

Dolphins - The sharks of the sea.
Advertisement
If that does not work, make sure you are outputting endl's at the end of the line. I opened up a test project and w/o them, I got no text, but after I added them, it worked fine.

- Drew
Adding Console I/O to a Win32 GUI App.
Thank you all for replying:
happybara and Drew_Benton: don't know why, but I tried both the tips and it still doesn't work.. my fault?

Oluseyi: I'm not using the win32 api. The project was initially set up with the SDL template of Dev-C++ wich includes windows.h just in order to use MessageBox(). I would like to keep the code as portable as possible, using only c++ standard libraries... thank you anyway for the link, it may come handy someday.

Ok then give C-styled output a try.

#include <stdio.h>printf("This is a test!\n");int val = 5;printf("Value of val: %i\n",val);


And as a side note, you are outputting *before* the breakpoint correct?

- Drew
Advertisement
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)

Quote:
And as a side note, you are outputting *before* the breakpoint correct?


I'm not debugging now, I'm just trying to make it work -sigh-

Quote: Original post by sand_man
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)

One solution is to recompile SDL.
Quote: Original post by Easca
Quote: Original post by sand_man
The above wont work because the stdout is no longer the console it is stdout.txt
I did see a solution to this problem not too long ago here somewhere, unfortunately i cant remember what it was :)

One solution is to recompile SDL.


I just clicked ahead a few posts from that link and this seems a little easier:

Quote: Actually, all that needs to be done is to recompile with "NO_STDIO_REDIRECT"
defined in src/main/SDL_main.c (you can either modify the file or re-compile
SDL_main.lib by hand with -DNO_STDIO_REDIRECT, your mileage may varry)
- A momentary maniac with casual delusions.

This topic is closed to new replies.

Advertisement