Simple Debug Output

Started by
2 comments, last by clearz 19 years, 7 months ago
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.
Advertisement
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 codefloat 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.
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.
Thanks for the posts guys both methods work great.

This topic is closed to new replies.

Advertisement