Sign in to follow this  
clearz

Simple Debug Output

Recommended Posts

Hi I am just after starting into the deep and wonderful world of DirectX programming in C++. Up until now the only language I really used was java and a bit of c++ console programming. In java even when you are programming using a GUI the console window is still visible. This is an indispensable tool for debugging where any output can be sent. I am looking to see if this is possible in C++ windows programming. A place where I can send int's, float's and string's for easy viewing during runtime. Does anyone know of a method of doing this./ thanks John.

Share this post


Link to post
Share on other sites
Try the OutputDebugString(), it takes a LPCTSTR but(if you don't know) you can make floats, int etc. to char* like this:

#include <stdio.h>

//Other code

float Angle=1.54f;
char Buffer[1024];
sprintf(Buffer,"Angle is %f",Angle);

//Other code


and then call "OutputDebugString(Buffer);" you need to include "Windows.h" to use OutputDebugString, i suppose you use Windows since you say you are working with DX.

Share this post


Link to post
Share on other sites
Rasmus gave you an excellent answer. I just wanted to point out that OutputDebugString sends its output to the debugger, which ends up displayed in the debug window within the IDE. This is the proper and better way to do it.

If you want to create a console for your Windows application for other purposes, however, use the AllocConsole API (and FreeConsole to clean it up). Again, this is not for debugging purposes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this