Advertisement Jump to content

Archived

This topic is now archived and is closed to further replies.

tomdavis

Using printf() in Windows programs

This topic is 5539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Use ofstreams instead.


#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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
Thank you LessBread, this is perfect. :-) No fuss, nice and simple. Now to fix the bug in my camera functions.

Cheers,
Tom

Share this post


Link to post
Share on other sites
Should this work with a Win32 console application using glut ?
I tried ; it compiles fine, but nothing happens ???

Share this post


Link to post
Share on other sites
..... thinking ...

what kind of console window is it ? Window style ? Or am''I
trying to open the console that already exists (dos style) :D ?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!