cout to console in SDL

Started by
40 comments, last by fastcall22 12 years, 5 months ago
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
Advertisement
Quote:Original post by Oluseyi
Adding Console I/O to a Win32 GUI App.


thanks for the link.
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
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):
#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
#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!
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
Ok at work I had sdl 1.2.4 I also assumed it would automatically give me the latest version through the package manager :-(.

Anyway at home I have SDl 1.2.7 installed and I also put in a copy of SDL 1.2.8 and both of them still print to stdout.txt.
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
Ah, well I'll just put up with the stdout.txt. It would be nice to be able to do it without recompiling though.

This topic is closed to new replies.

Advertisement