Sign in to follow this  

Turn an __int64 into a string...

This topic is 4163 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 guys! Got an easy one for you. Here's what I'm trying to do... StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%i", GStuff->P1_GameScore); Pretty easy. Put the value of "GStuff->P1_GameScore" into the char array "ScoreStr[]". The problem I'm having is this: P1_GameScore is a '__int64', because it can get to be a VERY big number. So when I call the above, not all of the number is put into the character array 'ScoreStr'. How do I get a '__int64' variable into a string (char array)? Thanks in advance for the help! [smile]

Share this post


Link to post
Share on other sites
You could also get it into a regular std::string (assuming you're using C++) just by doing:


__int64 big = 0x1234567890ABCDE;
std::strstream strm;
strm << big << std::ends;
std::string str = strm.str();

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"%llu" = long long unsigned int
"%lli" = long long int

this is what i know from gcc, it might be the same in VS03 and newer

Share this post


Link to post
Share on other sites
Quote:
Original post by mmelson
You could also get it into a regular std::string (assuming you're using C++) just by doing:

*** Source Snippet Removed ***


Um, how many years ago did you learn C++? It's spelled "stringstream" now, and there's no 'ends' nonsense any more.

OP:

1) Referring to char arrays as "strings" makes the baby Zahlman cry.
2) You do know that 32-bit signed integers range up to 2 billion and change, yes? Just what kind of game are you making o_O

Share this post


Link to post
Share on other sites
Thanks for the info, guys!

Yeah, __int64 is probably overkill since I only want the score to cap at 999,999,999. But when I used the "%i", I couldn't move that info into a char string (because the %i truncated the score value).

So what AP was mentioning:

"%llu" = long long unsigned int
"%lli" = long long int

that should work? I'm at school so I can't test that at the moment. So I should change:

__int64 GStuff->P1_GameScore;
...
StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%i", GStuff->P1_GameScore);


to this:

long unsigned int GStuff->P1_GameScore;
...
StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%llu", GStuff->P1_GameScore);


Does that look correct? Please let me know and I'll try it out when I get home later today. Thanks again for the help!

Share this post


Link to post
Share on other sites

This topic is 4163 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this