如何在C ++ / Windows中输出到控制台 [英] How to output to the console in C++/Windows

查看:335
本文介绍了如何在C ++ / Windows中输出到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上使用C ++中的iostream时,它会在终端中显示程序输出,但在Windows中,它只是将输出保存到stdout.txt文件中。

When using iostream in C++ on Linux, it displays the program output in the terminal, but in Windows, it just saves the output to a stdout.txt file. How can I, in Windows, make the output appear in the console?

推荐答案

因为你提到stdout.txt我google'd它看到什么将创建一个stdout.txt;通常,即使使用Windows应用程序,控制台输出到分配的控制台,或者如果没有分配控制台,则无处。

Since you mentioned stdout.txt I google'd it to see what exactly would create a stdout.txt; normally, even with a Windows app, console output goes to the allocated console, or nowhere if one is not allocated.

因此,假设您使用SDL只有带来stdout.txt的事情),您应该遵循此处的建议。要么freopen stdout和stderr与CON,或做其他链接器/编译解决方法。

So, assuming you are using SDL (which is the only thing that brought up stdout.txt), you should follow the advice here. Either freopen stdout and stderr with "CON", or do the other linker/compile workarounds there.

如果链接再次断开,这里正是引用了什么libSDL:

In case the link gets broken again, here is exactly what was referenced from libSDL:


如何避免创建stdout.txt和stderr.txt?

How do I avoid creating stdout.txt and stderr.txt?

我相信在SDL附带的Visual C ++项目中有一个SDL_nostdio目标>你可以构建你想要什么(TM)。

"I believe inside the Visual C++ project that comes with SDL there is a SDL_nostdio target > you can build which does what you want(TM)."

你定义NO_STDIO_REDIRECT并重新编译SDL,我想它会解决这个问题。 >>(由Bill Kendrick提供)

"If you define "NO_STDIO_REDIRECT" and recompile SDL, I think it will fix the problem." > > (Answer courtesy of Bill Kendrick)

这篇关于如何在C ++ / Windows中输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆