user969416
user969416

Reputation:

Unusual iostream happenings in C++?

I have the following program which compiles fine and with no errors or warnings:

#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include "classes.h"

int width = 0;
int height = 0;

int init(int width = 640, int height = 480, int bpp = 32) // needs to be the first  statement called in main()

{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_SetVideoMode(width, height, bpp, SDL_OPENGL);
    SDL_WM_SetCaption("SpaceInvaders", NULL);
    glClearColor(0,0,0,0);
}

void setstates(int width = 640, int height = 480) // needs to be called when the    window is resized
{
    ::width = width;
    ::height = height;
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int main (int argc, char** argv)
{
    setstates();
    std::cout << ::width << std::endl;
    std::cout << ::height << std::endl;

    int a ;
    std::cin >> a;

    return 0;
}

What I am finding curious is when I call cout in the main function and I am running the program, the console appears and displays nothing, when I press a letter and enter, the program returns 0 as if it were at the cin statement but the console will not even display the letter I have pressed.

I do however get a stdout.txt document in the compiled program directory with what is apparently the cout'ed information formatted by a newline as it is in the program.

Therefore my question is what is the problem? and why is this happening, I have never experienced it before.

Thank you for your time in advance

Upvotes: 1

Views: 268

Answers (1)

themel
themel

Reputation: 8895

SDL redirects your output, as mentioned in the FAQ.

Upvotes: 3

Related Questions