Printf is not printing anything to output? C++ SDL
Solution 1
SDL by default redirects stdout to a file, stdout.txt. You should find it in your program's working directory.
Solution 2
Bring up the projects properties, go to linker->system->subsystem and change it to the third option, CONSOLE. That should do it
Solution 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.
Solution 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(includeWindows.h)
Solution 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?.
Related videos on Youtube
Qasim
Software developer working on Outlook for iOS. Student at University of Toronto. 20 years old.
Updated on July 22, 2022Comments
-
Qasim 5 monthsI 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?
-
Qasim over 10 yearsPutting a breakpoint at the return statement, I don't know where to look for the console. When pressing Ctrl+F5, the Output view remains empty, but when I just use F5 the output shows build logs and debug logs, with it containing the following: pastebin.com/UKWpCKsD Do all the PDB errors play a role in this? -
Qasim over 10 yearsSadly there is still no output! I am wondering what could be causing this. Very absurd. -
Superman over 10 yearsThe PDB errors that you're seeing don't matter. Check the return value of printf. It returns the number of characters that has been printed. printf outputs characters in a separate console window and not in the output view. -
Qasim over 10 yearshow do I get access to the seperate console window? -
Superman over 10 yearsWhen you do Ctrl+F5 there will a console window open. Check your taskbar. -
Qasim over 10 yearsNo console is ever opened. It is just the output window. -
Superman over 10 yearsLooks like you've not created a console application. printf outputs to the console. Use OutputDebugString instead. -
Qasim over 10 yearsThank you. This file is created in Visual C++ project Debug folder, containing all the "std::cout" functions I call. -
Bram almost 8 yearsThis is for SDL1.2 only, does not work for SDL2. As you search the source code for SDL2, you will see this symbol is not being used.