Jump to content
  • Advertisement

Archived

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

zackriggle

Problems with Num->String

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

Alright, this is not some dumb question about how (I know about itoa() ), but about a problem that it causes me. When it changes a number from its original form to a string, it cuts out any 0's before the actual numbers. Is there a way I can get it to leave these in? Example: long lMyNum = 0x0000F8AC; char *cpMyString; cpMyString = new char[8]; itoa(lMyNum,cpMyString,16); cout << ":" << lMyNum << ":" << endl; This small bit of code writes out ":F8AC:". I want it to write out ":0000F8AC:". This way, I can use it with my sockets stuff, and just place the length as a 4-byte ascii value (translated to a WORD via atoi(), and yes, I know I used a DWORD in the example), without having to put another single-character value in front of that (telling the length of the value that tells me the length of the rest of it). ----What I want: string: "Four" length: 4 send it as: 04Four ----What I have to do now: string: "Four" length: 4 sends as: 104Four Granted, it is not a whole lot of work to do, it is just annoying... [edited by - zackriggle on April 19, 2003 4:53:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Use sprintf() instead and you can format as you want.

Share this post


Link to post
Share on other sites
Another thing to use is strstream which allows cout style formatting to a string. Look it up in your compiler docs.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!