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

老子叫甜甜 提交于 2019-11-30 12:11:05

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

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

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.

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)

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?.

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

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).

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.

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