printf 不打印任何东西输出?C++ SDL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11068565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Printf is not printing anything to output? C++ SDL
提问by Qasim
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.
我试图在我的 Visual C++ 项目中使用“printf”,但它不起作用。使用 Lazy Foo 的教程,我在我的项目中设置了 SDL,但是当我播放它时,printf 没有做任何事情。
#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?
就是这样。可能有什么问题?
采纳答案by jrok
SDL by default redirects stdout to a file, stdout.txt
. You should find it in your program's working directory.
默认情况下,SDL 将标准输出重定向到一个文件stdout.txt
. 您应该可以在程序的工作目录中找到它。
回答by DaKrazyKatt
Bring up the projects properties, go to linker->system->subsystem and change it to the third option, CONSOLE. That should do it
调出项目属性,转到链接器->系统->子系统并将其更改为第三个选项,CONSOLE。那应该这样做
回答by thiagoh
In Linker -> System
in your project's properties, check that the SubSystem is
"Console (/SUBSYSTEM:CONSOLE)"
.
在Linker -> System
项目的属性中,检查 SubSystem 是否为
"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.
这会导致在您运行程序时出现一个单独的控制台窗口。如果您当前的入口点不是主要的,那么如果您这样做,则需要将其更改为该入口点。
回答by ta.speot.is
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
:
如果要将某些内容记录到输出窗口,请使用OutputDebugString
:
Sends a string to the debugger for display.
void WINAPI OutputDebugString( __in_opt LPCTSTR lpOutputString );
Header
WinBase.h
(includeWindows.h
)
将字符串发送到调试器进行显示。
void WINAPI OutputDebugString( __in_opt LPCTSTR lpOutputString );
标题
WinBase.h
(包括Windows.h
)
回答by talles
Try defining NO_STDIO_REDIRECT.
尝试定义 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?.
如果这不起作用,请尝试此链接中的解决方案:如何获取控制台输出而不是 stdout.txt 和 stderr.txt?.
回答by Shawn Buckley
Printf usually needs a newline to update the console. Add a '\n' character to the end and re-run the program.
Printf 通常需要换行来更新控制台。在末尾添加一个 '\n' 字符并重新运行程序。
回答by Superman
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.
您可能看不到输出,因为您正在 Visual Studio 中按 F5 运行程序,并且控制台窗口在程序退出后关闭。
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.
您可以执行以下 3 件事之一 -
在 return 语句中放置一个断点。
在 return 语句之前放置一个 getchar() 语句。
通过按 Ctrl+F5 而不是 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).
您也可以直接从命令提示符 (cmd.exe) 运行 EXE。
回答by Tariq Mehmood
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.
当您运行/调试程序时,有一个 Visual Studio 的输出窗口。您应该能够在该窗口中看到输出。