Jump to content
  • Advertisement

Archived

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

Roaders

Debugging, strings and floats.

This topic is 5676 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

I am trying to find out the value of 3 flots in a D3DXMATRIX object. I am using DXTRACE_MSG to output debug messages but can''t figure out how to turn the floats in to strings so that I can output a message. I have been messing worund with string and have this code: string test("hello, I am a test"); char nullString[256]; strcpy(nullString,test.c_str()); DXTRACE_MSG(nullString); That outputs "hello, I am a test" but I can''t find anything on getting a float in there. Hope you can help Thanks

Share this post


Link to post
Share on other sites
Advertisement
I''ve written a routine for that, but can''t find it right now. I''ll try and dig it out for you.



(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus

Share this post


Link to post
Share on other sites
You could simply include and use sprintf...


char nullMessage[256];
float x= 10.1f;

sprintf(nullMessage,"This is a test %f",x);

DXTRACE_MSG(nullMessage);



(%f = float, %s = string (null terminated char array), %d = integer, %x = hex, %c = char).

Share this post


Link to post
Share on other sites
Another way to do it if you want to use stl:


#include <sstream>
...
directx includes
...
using namespace std;
...
stringstream s;
float x=10.1f;

s << "this is x: " << x << ends;

DXTRACE_MSG(s.str().c_str());
...
...


EDIT: Sorry, forgot the using declaration and the 'ends'.

[edited by - fizban75 on June 5, 2003 11:50:22 AM]

Share this post


Link to post
Share on other sites
Thanks for that fizban but when I try that code I get a load of compilation errors:

d:\My Documents\MSC\AIRacer\cCamera.cpp(84): error C2065: ''stringstream'' : undeclared identifier
d:\My Documents\MSC\AIRacer\cCamera.cpp(84): error C2065: ''s'' : undeclared identifier
d:\My Documents\MSC\AIRacer\cCamera.cpp(86): error C2296: ''<<'' : illegal, left operand has type ''''unknown-type''''
d:\My Documents\MSC\AIRacer\cCamera.cpp(86): error C2297: ''<<'' : illegal, right operand has type ''char [12]''
d:\My Documents\MSC\AIRacer\cCamera.cpp(87): error C2228: left of ''.str'' must have class/struct/union type
d:\My Documents\MSC\AIRacer\cCamera.cpp(87): error C2228: left of ''.c_str'' must have class/struct/union type

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You need to either put in "using namespace std;" or change "stringstream" to "std::stringstream" because stringstream is in the namespace std.

Share this post


Link to post
Share on other sites
Getting there. I now get:

''DXTraceA'' : cannot convert parameter 4 from ''const char *'' to ''char *''

Share this post


Link to post
Share on other sites
DXTRACE_MSG takes a char *? Wonder why. Anyway, just cast to (char *) like so:

DXTRACE_MSG((char *)(s.str().c_str()));

Share this post


Link to post
Share on other sites
That did it. Thanks a lot for all of te help guys. I did get it to work wil nullstings (thanks to your help):

char nullString[256];
char nullString2[256];
sprintf(nullString," velocity X: %f",(float)D3DVEcCarVelocity[0]);
sprintf(nullString2," Y: %f",(float)D3DVEcCarVelocity[1]);
strcat(nullString,nullString2);
sprintf(nullString2," Z: %f",(float)D3DVEcCarVelocity[2]);
strcat(nullString,nullString2);
DXTRACE_MSG(nullString);

But using STL it is much neater:

stringstream s;
s << "velocity X: " << D3DVEcCarVelocity[0] << " Y: " << D3DVEcCarVelocity[1] << " Z: " << D3DVEcCarVelocity[2];
DXTRACE_MSG((char *)s.str().c_str());

Thanks again

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!