SDL控制台输出在调试时工作,但在使用exe运行时不起作用 [英] SDL Console output works when debuging, but not when run with the exe
问题描述
我在写一个实验性网络程序,基本上是一个用于学习网络的测试程序。我使用SDL和SDL_net在Code :: Blocks与mingw,所以控制台输出被定向到stdout.txt。我搜索一下,发现你可以通过包括在SDL_Init()后修复这个问题:
I am writing an experimental networking program, basically a test program for learning networking. I am using SDL and SDL_net in Code::Blocks with mingw, so the console output was being directed to stdout.txt. I searched around and found that you can fix this by including after SDL_Init():
freopen("CON", "w", stdout); //stops redirect of output
freopen("CON", "w", stderr); //and errors...
这个工作完美,但是只有当构建和运行程序IDE:当在IDE外部运行时(例如双击程序),程序运行正常,除了控制台输出(仍然为空白)。由于程序应该是一个控制台程序这是一个严重的问题...我不想总是运行程序在IDE中使用它。
This worked perfectly, but only when building and running the program in the IDE: when run outside of the IDE ( e.g. double clicking on the program) the program runs properly, with the exception of the console output, which is still blank. As the program is supposed to be a console program this is a severe problem... I don't want to have to always run the program in the IDE to use it.
任何解决方案都是apreciated,但我更喜欢这是一个改动的代码,虽然在夹捏一个批处理文件将做(我已经读了几个帖子,这是唯一的作品,但他们没有' t进入更多的细节,所以我不能复制它)。感谢。
Any solution is apreciated but I would prefer that it was an alteration to the code, although in a pinch a batch file will do (I've read a couple of posts where this is the only thing that works, but they didn't go into much detail, so I can't replicate it). Thanks.
推荐答案
您看过 SDL控制台常见问题?
他们提供了许多建议,包括:
They provide many suggestions, including:
首先尝试
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
如果无法使用(例如您的情况),请尝试
If it doesn't work (like in your case), try
#include <fstream>
#include <iostream>
using namespace std;
....
ofstream ctt("CON");
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
...
ctt.close();
或
FILE * ctt = fopen("CON", "w" );
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
...
ctt.close();
另一个选项是重新编译 SDLmain
库或者将 SDLmain
代码添加到您的项目中,并停止与库的链接。
Another option is to recompile the SDLmain
library or add the SDLmain
code to your project and stop linking against the library.
这篇关于SDL控制台输出在调试时工作,但在使用exe运行时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!