简体   繁体   English

C ++中出现异常的iostream事件?

[英]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. 我感到奇怪的是,当我在主函数中调用cout并运行程序时,控制台出现并且什么也不显示,当我按一个字母并输入时,程序返回0就像在cin语句中一样,但是控制台甚至不会显示我按下的字母。

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. 但是,我确实在编译后的程序目录中获得了一个stdout.txt文档,其中的内容显然是程序中换行符所格式化的cout信息。

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 谢谢你的时间

SDL重定向您的输出,如FAQ所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM