Using printf() in Windows programs
Hello,
I''m trying to program a 3D game using Nehe''s tutorials as a basis. I''ve been hitting a few bugs and would really like to stick a couple of printf()''s in to output variable values and so on.
I can''t work out how to get hold of this output-- is there any way to make a console appear with this output in it. I''m using MS Visual C++ to develop my program, does this provide any features like this?
Thanks in advance, any help would be much appreciated,
Tom Davis
Use ofstreams instead.
Reason? In Windows, anything you output to the console needs to be redirected and that implies a whole mess of things you need to do - it's easier to use streams and output stuff to files. Just keep ind mind that the OS has a symbolic limit on the number of files at any given time.
edit: added "at any given time"
[edited by - crispy on November 18, 2003 3:05:53 PM]
#include <fstream>using namespace std;main(){ ofstream out("myfile.txt"); //presumes ASCII mode out << "error!" << endl; out.close(); }
Reason? In Windows, anything you output to the console needs to be redirected and that implies a whole mess of things you need to do - it's easier to use streams and output stuff to files. Just keep ind mind that the OS has a symbolic limit on the number of files at any given time.
edit: added "at any given time"
[edited by - crispy on November 18, 2003 3:05:53 PM]
Nice 1 Crispy ive been writing an app for a while and have had to have a console app running along side it to produce output for debugging but you just saved me lots of effort
Excellent, thanks for the help. :-)
One other quick question-- is there an equivalent of the "tail -f " *NIX command? So I can keep an eye on what''s being written to the file in realtime (rather than after execution has finished).
Thanks,
Tom
One other quick question-- is there an equivalent of the "tail -f " *NIX command? So I can keep an eye on what''s being written to the file in realtime (rather than after execution has finished).
Thanks,
Tom
Popping a console with a gui based program isn''t difficult.
To pop a console and setup stdout:
AllocConsole();
freopen("CONOUT$", "wb", stdout);
To clean up afterward:
fclose(stdout);
FreeConsole();
To pop a console and setup stdout:
AllocConsole();
freopen("CONOUT$", "wb", stdout);
To clean up afterward:
fclose(stdout);
FreeConsole();
Also even if you set up a Console app, you can still create windows and do pretty much anything you can in a Windows app. Just have a traditional main function instead of a WinMain one.
Your instance handle can be found using GetModuleHandle.
Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Your instance handle can be found using GetModuleHandle.
Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Thank you LessBread, this is perfect. :-) No fuss, nice and simple. Now to fix the bug in my camera functions.
Cheers,
Tom
Cheers,
Tom
Should this work with a Win32 console application using glut ?
I tried ; it compiles fine, but nothing happens ???
I tried ; it compiles fine, but nothing happens ???
..... thinking ...
what kind of console window is it ? Window style ? Or am''I
trying to open the console that already exists (dos style) :D ?
what kind of console window is it ? Window style ? Or am''I
trying to open the console that already exists (dos style) :D ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement