cout to console in SDL

Started by
40 comments, last by fastcall22 12 years, 5 months ago
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!
Advertisement
Quote:Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!

Did you try using:

freopen( "stdout.txt", "wt", stdout );
freopen( "stderr.txt", "wt", stderr );

Quote:Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!


Are you aware that the file deletes itself after your program ends? To make anything of it you'll most likely run your program in windowed mode and look at the text file during debugging/testing.

Edit: If nothing is written to it :)

[Edited by - Rhaal on February 10, 2005 5:43:36 PM]
- A momentary maniac with casual delusions.
Quote:Original post by Rhaal
Quote:Original post by cignox1
Ok. The funny thing is that I don't even get the stdout.txt file. Uhm... I will use some font library (I would have to use it however, soon or later).
Thank you again!


Are you aware that the file deletes itself after your program ends? To make anything of it you'll most likely run your program in windowed mode and look at the text file during debugging/testing.


It should only do that when no text is sent there. If the file contains text, it is left intact.
Quote:
freopen( "stdout.txt", "wt", stdout );
freopen( "stderr.txt", "wt", stderr );


Uh, I thought that it would have been opened from the program without specific instructions...
Quote:Original post by cignox1
Quote:
freopen( "stdout.txt", "wt", stdout );
freopen( "stderr.txt", "wt", stderr );


Uh, I thought that it would have been opened from the program without specific instructions...


No, your right. That is what SDL does auto. One last thing to try before I say throw in the towel. happybara's first post mentioned this, but maybe it was the use of the parameters that made it fail. Instead try using:
freopen( "CON", "w", stdout ); 


As you can see, there is no 't'. I got that idea from this MSDN Article. If that does not solve your problems, well then I'm sorry, I guess there is nothing you can really do. Best of luck!

- Drew
Thank you again... but guess what? It doesn't work! I always hated console interfaces, I never liked to use them, and I always had to work with them... once that I need a simle output on a console, there is no way to make it work!
Allright, I will solve this problem in the future. First I have to being able to invert a matrix, but I already opened a topic about that.
This might seem sort of obvious but use the freopen( "CON", "w", stdout ); call after sdl_init(); since SDL_init(); is the call that calls
freopens ("CON",w/e,"stdout.txt");.. It worked awesome for me....
added to the SDL FAQ since i see it a lot

http://www.libsdl.org/cgi/docwiki.cgi/FAQ_20Console

worked for you guys? AFTER SDL_Init?
Working on a fully self-funded project
Quote:Original post by Madster
added to the SDL FAQ since i see it a lot

http://www.libsdl.org/cgi/docwiki.cgi/FAQ_20Console

worked for you guys? AFTER SDL_Init?


It does not matter to me really since I am not a Dev-CPP user, but it did not work for me. I think it may be of the DevPak that I am using. I will try updating my SDL from a non-3rd party source.
#include <SDL/SDL.h>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;/* The screen surface */SDL_Surface *screen = NULL;int main(int argc, char *argv[] ){    char *msg;    int done;    // Initialize SDL //    if (SDL_Init (SDL_INIT_EVERYTHING) < 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);    }    freopen( "stdout.txt", "w", stdout );    freopen( "stderr.txt", "w", stderr );        cout << "Test" << endl;    printf("Test");        done = 0;    while (!done)    {        SDL_Event event;        // Check for events //        while (SDL_PollEvent (&event))        {            switch (event.type)            {            case SDL_KEYDOWN:                 if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }                 done = 1;                break;            case SDL_QUIT:                done = 1;                break;            default:                break;            }        }    }    return 0;}


[edit] Yea it still doesn't work. Once I add SDL to a new project, the project stops working correctly. I do not know why this is happening. I will try one more thing though.

I even tried a reinstall of Dev, then I tried 1.2.7 first, then 1.2.8 and still couldn't get it to work. Sheesh what's going on. I guess it has to be something we are doing if it works for you guys fine.

[Edited by - Drew_Benton on February 13, 2005 11:00:05 PM]

This topic is closed to new replies.

Advertisement