🔒 Locked
cout to console in SDL
Advertisement
Original Post
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!
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
- Drew
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.
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.
And as a side note, you are outputting *before* the breakpoint correct?
- Drew
#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
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)
I cannot see why this is not working. Can you please post your code. It makes no sense that none of the suggestions have yet to work. What OS and IDE are you using? What version of SDL as well. My cout and printf work fine in Dev, VS6, and VS7, so there's one detail that is missing somewhere.
- Drew
- Drew
Quote:
Original post by Drew_Benton
I cannot see why this is not working. Can you please post your code. It makes no sense that none of the suggestions have yet to work. What OS and IDE are you using? What version of SDL as well. My cout and printf work fine in Dev, VS6, and VS7, so there's one detail that is missing somewhere.
- Drew
I don't get any output on the console. I didn't try the winapi redirects though.
I use dev-cpp 4.9.9.1 and SDL 1.2.4. The freopen works fine if I just put a arbituary filename and stops any output to stdout.txt using freopen( "CON", "wt", stdout ).
#include <stdio.h>#include <stdlib.h>#include <SDL/SDL.h>/* The screen surface */SDL_Surface *screen = NULL;int main (int argc, char *argv[]){ int done; printf( "Hello World1\n"); /* Initialize SDL */ if (SDL_Init (SDL_INIT_VIDEO) < 0) { printf ("Couldn't initialize SDL: %s\n", SDL_GetError ()); exit (1); } atexit (SDL_Quit); freopen( "CON", "wt", stdout ); //hello world2 doesn't get outputted// freopen( "filename", "wt", stdout ); //hello world2 goes to filename printf( "hello world2\n"); exit( 0 );}It is compiled as a console application (Win32 console).
Well, that's my code (just the basic stuff):
The Dev-C++ version is 4.9.9.1 with SDL version 1.2.4. Note that the program I tested was initially created by the Dev template, but I think that this makes no differences since parameters should be the same.
#include <stdio.h>#include <stdlib.h>#include "SDL.h"#include <iostream>using namespace std;/* The screen surface */SDL_Surface *screen = NULL;intmain (int argc, char *argv[]){ char *msg; int done; freopen( "CON", "wt", stdout ); freopen( "CON", "wt", stderr ); printf("ciccio\n"); /* Initialize SDL */ if (SDL_Init (SDL_INIT_VIDEO) < 0) { sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ()); free (msg); exit (1); } atexit (SDL_Quit); /* Set 640x480 16-bits video mode */ screen = SDL_SetVideoMode (640, 480, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) { sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n", SDL_GetError ()); free (msg); exit (2); } SDL_WM_SetCaption ("SDL MultiMedia Application", NULL); done = 0; while (!done) { SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: break; case SDL_QUIT: done = 1; break; default: break; } } } return 0;}The Dev-C++ version is 4.9.9.1 with SDL version 1.2.4. Note that the program I tested was initially created by the Dev template, but I think that this makes no differences since parameters should be the same.
I will take a look at the code, but I am sure the problem lies in the fact you are using SDL 1.2.4. However, you are free to use it, but take a look at all the updates made! I would strongly suggest using at least version 1.2.7, but once again, you are free to use whatever you want. I know I have 1.2.8 and my console functions work just fine, cout and c-style alike. I'd say download a more recent version, but do not install over your current, simply make a test project, and move the files into that project and see if you get the same errors.
Instead of linking SDL.lib and such, use relative path names - ie
That's just an example of what you can do. I think it would be better for whatever you are doing because of the serious bugs that are fixed as of 1.2.7, but you can determine that for yourself.
- Drew
Instead of linking SDL.lib and such, use relative path names - ie
#pragma comment ( lib, "C:\\sdl 1.2.7\\lib\\sdl.lib" )That's just an example of what you can do. I think it would be better for whatever you are doing because of the serious bugs that are fixed as of 1.2.7, but you can determine that for yourself.
- Drew
First of all thank you for having point out that there are more recent versions of sdl... I'm so lazy that I trusted that if it were a new version, it would have been released as package for Dev-C++ (sometimes I feel stupid :-( ((Uh, this sentences were too complex for my bad english: I hope they are at least understandable))
Second: it still doesn't work. I will try others configurations (don't know if #pragma used to link libraries is supported by Dev-C++, I thought that it was VC++ specific).
@Easca: could you tell me if the problem was solved on your system by updating SDL? (...if you want to update it, of course)
Thank you all anyway!
Second: it still doesn't work. I will try others configurations (don't know if #pragma used to link libraries is supported by Dev-C++, I thought that it was VC++ specific).
@Easca: could you tell me if the problem was solved on your system by updating SDL? (...if you want to update it, of course)
Thank you all anyway!
Ahh! [lol] I'm sorry, I got confused and thought that Easca was the OP. Ok for dev-cpp that #pragma will not work for the most part with SDL, so I would just copy the current version of SDL you have to a folder then install the new one. Then you can try your program again, since the linker libs will now be updated. Do not forget to update the .DLL in the system directory as well.
- Drew
- Drew
Ok I'd like to say sorry for not trying out my suggestions first. I was using VS6 and VS7 the whole time and it worked fine. I am thinking that the only way to fix this under Dev-CPP and MingGW is by recompiling per the response to the link that Easca posted. I tried the redirecting output myself and could not get it to work either. I then tried Oluseyi's link as well, but it failed the same. As of now that is all I can think of.
- Drew
- Drew
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement