Printf is not printing anything to output? C++ SDL

我的未来我决定 提交于 2019-11-30 14:54:24

问题


I am trying to use "printf" in my Visual C++ project however it is not working. Using Lazy Foo's tutorial, I set up SDL in my project, but when I play it, printf doesnt do anything.

#include "SDL.h"
#include <stdio.h>

int main( int argc, char* args[] ) {
    printf("Testing");
    return 0;
}

The output looks like this:

The program '[4664] SDL Testing.exe: Native' has exited with code 0 (0x0).

And that's about it. What could be wrong?


回答1:


SDL by default redirects stdout to a file, stdout.txt. You should find it in your program's working directory.




回答2:


Bring up the projects properties, go to linker->system->subsystem and change it to the third option, CONSOLE. That should do it




回答3:


In Linker -> System in your project's properties, check that the SubSystem is "Console (/SUBSYSTEM:CONSOLE)".

That causes a separate console window to be brought up when you run your program. If your current entry point isn't main, then you'll need to change it to that if you do this though.




回答4:


Everything works, I have even displayed an image to the screen, but I cannot program without having someway to output messages

I assume this means that your have a window available to you, not a console.

If you want to log something to the output window, use OutputDebugString:

Sends a string to the debugger for display.

void WINAPI OutputDebugString(
  __in_opt  LPCTSTR lpOutputString
);

Header WinBase.h (include Windows.h)




回答5:


Try defining NO_STDIO_REDIRECT.

#define NO_STDIO_REDIRECT

If that doesn't work try the solution in this link: How can I get console output instead of stdout.txt and stderr.txt?.




回答6:


Printf usually needs a newline to update the console. Add a '\n' character to the end and re-run the program.




回答7:


You're probably not seeing the output because you're running the program from within Visual Studio by pressing F5 and the console window closes after the program exits.

You can do one of the 3 things -
Put a breakpoint at the return statement.
Put a getchar() statement before the return statement.
Run the program by pressing Ctrl+F5 instead of F5.

All of the above will cause the console window to remain on the screen.

You could also directly run the EXE from a command prompt (cmd.exe).




回答8:


there is an output window of visual studio when you are running/debugging your program. You should be able to see the output in that window.



来源:https://stackoverflow.com/questions/11068565/printf-is-not-printing-anything-to-output-c-sdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!