Jump to content
  • Advertisement

Archived

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

Megatron

Converting int's to char* 's

This topic is 5886 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 have a font rendering function that takes a char* as its first argument. The trouble is, I want to print out a number that has to have operations performed on it. So if I have something like int hitPoints = 100; and I want to change hitPoints into char* text so I can call RenderFont(text,.....); What should I do?

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming that you (Megatron) aren't aware that char* parameters are used to pass the address of the first character of a string—a C-style string (array of characters). So, you want to convert an int to a [C-style] string. That's what you'll ask for. It's not just pedanticism because the answer to your question, exactly how it was asked, is: (char*)myint .


[edited by - merlin9x9 on April 29, 2002 9:40:55 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
It''s not just pedanticism because the answer to your question, exactly how it was asked, is: (char*)myint .


Nope.

"I want to change hitPoints into char* text"

Changing hitPoints into text is not the same as casting it to char *.

Share this post


Link to post
Share on other sites
That''s how you phrased it in your message subject line, and that''s what I meant. But from what I actually said, you''re absolutely right.

Share this post


Link to post
Share on other sites
I hate std::string. It sucks. What were they injecting into themselves when they came up with the idea of using the << and >> operators? Oluseyi's std version is so confusing and nonintuitive. That's what I don't use the STL.

~CGameProgrammer( );

[edited by - CGameProgrammer on April 29, 2002 12:19:07 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by CGameProgrammer Oluseyi's std version is so confusing and nonintuitive. That's what I don't use the STL.



    
string tostring(int n)
{
ostringstream out;
out<<n;
return out.str();
}

Hide that away somewhere and all you'll ever have to see is tostring()...happy?

Oh, and std::string doesn't use << and >>. That would be STREAMS you're talking about.

[edited by - sjelkjd on April 29, 2002 12:39:43 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!