简体   繁体   中英

Get command line when I run C++ program with SDL

I have a basic program to create a window with SDL and the only thing it gives me when I compile and run the program is a command line prompt that says Press <RETURN> to close this window... i am not sure what is causing this. Does someone know how to fix this?

here is the main.cpp file

#include <iostream>
#include <SDL2/SDL.h>

int main(int argc, char* argv[]) {

    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window;

    window = SDL_CreateWindow(
                "Requiem",
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                640,
                480,
                SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL
             );

    if(window == NULL) {
        std::cout << "Could not create window: " << SDL_GetError() <<  std::endl;
        return 1;
    }

    SDL_Delay(3000);

    SDL_DestroyWindow(window);

    SDL_Quit();
    return 0;
}

and here is the .pro if needed

TEMPLATE = app
CONFIG += console
CONFIG -= qt

LIBS += -L C:/Users/Zach/Documents/dev/libs/SDL2-2.0.1/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2
INCLUDEPATH += C:/Users/Zach/Documents/dev/libs/SDL2-2.0.1/i686-w64-mingw32/include

SOURCES += main.cpp

and a picture of what I see

在此输入图像描述

Go to the project settings, and go to the "run" tab, and then uncheck "Run in Terminal".

Then go in your .pro file and comment out "CONFIG += console".

Then go to Project > Clean All.

Then rebuild and run your project.

EDIT:

That will make it so that the stdout and the stderror gets redirected to the "Application Output" tab in Qt Creator.

The reason your std::cout didn't show up is probably because it didn't get flushed out. You have to end a line for it to go out.

std::cout << "Some text" << std::endl;

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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