Jump to content
  • Advertisement

Archived

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

skrwX

Converting float to strings

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

Hi everybody! I want a fps-counter in my game(for testing purposes) and I want the fps to appear on my screen. I use the TextOut function but cannot convert the fps(in float) to a string that TextOut can work with! How can I convert this sucking fps? (I don''t use the MFC! So no CString-blabla..)

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
wsprintf(), a Win32 API, may also help you

Kwanji

Share this post


Link to post
Share on other sites
While I usually use sprintf when i only have 1 little variable to convert to a string, if you are using C++, you may want to look into the stringstream classes (or strstream in some implementations). These classes do all of the stuff you are used to when sending variables out to a file or cin. code like this:

// START CODE
struct Person
{
int age;
float height;
};

Person me;

cout << "Age: " << me.Age << "Height: " << me.Height << endl;
// END CODE

would automatically convert the int and float for you ... right?

well that''s what stringstreams do.

you do this instead of above:

//CODE
ostringstream buff;
buff << myFloat << myInt << 43.76 << "YEAH!" << endl;

and then buff is set to a line of text just like a text file or console would be.

you access the buffer with the function str(void);

like:

RenderFPSOnScreen(buff.str());

good luck!

Share this post


Link to post
Share on other sites
a note, wsprintf() doesn''t work with floating point numbers (according to MSDN anyway

if you want floating point, you''d need to use sprintf()

adamm@san.rr.com

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!