How to output to the console in C++/Windows(如何在 C++/Windows 中输出到控制台)
问题描述
在 Linux 上的 C++ 中使用 iostream 时,它会在终端中显示程序输出,但在 Windows 中,它只是将输出保存到 stdout.txt 文件中.在 Windows 中,如何使输出显示在控制台中?
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,我就用谷歌搜索看看究竟是什么会创建一个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 的东西),您应该遵循建议 这里.使用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 中输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C++/Windows 中输出到控制台


基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01