PDA

View Full Version : C++ help? Please?


tkups
04-03-2005, 05:07 PM
How do I cast ints as strings? If I just do:

int x = 55;
string y = x;

It takes the ASCII code and makes it a letter or symbol. How do I retain the numerals in string form?

Cybren
04-03-2005, 05:08 PM
A bunch of swithces?

JokersJizz
04-03-2005, 05:08 PM
You can use modulus to read each digit as a char and string em together that way.

Town Bicycle
04-03-2005, 05:09 PM
I can hear Gregg running to WFN this post as we speak.

:P

JokersJizz
04-03-2005, 05:09 PM
I can hear Gregg running to WFN this post as we speak.

:P
That rule doesn't apply to tJP. Everyone knows that. Except you, n00b.

Town Bicycle
04-03-2005, 05:10 PM
That rule doesn't apply to tJP. Everyone knows that. Except you, n00b.
Well .... someone could've posted a memo or something.

:shakefist

tkups
04-03-2005, 05:11 PM
You can use modulus to read each digit as a char and string em together that way.

Yeah, modulus... mmmhmmmm...

????


edit: Hell, I don't even know if that was a typo and supposed to be modules, or if there is something called modulus in c++

JokersJizz
04-03-2005, 05:11 PM
Yeah, modules... mmmhmmmm...

????
The remainder thingy ---> %

also known as the modulus function.

edit: eg. 10%3=1. 12%5=2 14%7=0.

just use x%10, x%100, x%1000, etc.

ThatOneDude02
04-03-2005, 05:15 PM
How do I cast ints as strings? If I just do:

int x = 55;
string y = x;

It takes the ASCII code and makes it a letter or symbol. How do I retain the numerals in string form?Try adding 48 before converting to a string.

EDIT: Nevermind. That's only for one digit numbers.

JokersJizz
04-03-2005, 05:15 PM
Try adding 42 before converting to a string.
fixed.

tkups
04-03-2005, 05:16 PM
The remainder thingy ---> %

also known as the modulus function.

edit: eg. 10%3=1. 12%5=2 14%7=0.

just use x%10, x%100, x%1000, etc.

As in...
int x = 1234;
char y = x%10; //y = 4 now
int z = (int)(x*.1);//so z is 123, lopped of the 4
char a = x%10; //a = 3 now
int b = (int)(z*.1);//so z is 12, lopped of the 3
char c = x%10; //c = 2 now
int d = (int)(b*.1);//so d is 1, lopped of the 2
char e = d;// with onyl one digit left, straight assignment.

Then what do you do with the chars?

rub the bear
04-03-2005, 05:18 PM
String them together using quantum.

JokersJizz
04-03-2005, 05:19 PM
As in...
int x = 1234;
char y = x%10; //y = 4 now
int z = (int)(x*.1);//so z is 123, lopped of the 4
char a = x%10; //a = 3 now
int b = (int)(z*.1);//so z is 12, lopped of the 3
char c = x%10; //c = 2 now
char d = c;// with onyl one digit left, straight assignment.

Then what do you do with the chars?
Hmmm I'm not sure, but I remember that you had to convert digits to chars and then use the chars to make a string, I haven't done c++ in a couple years...

tkups
04-03-2005, 05:20 PM
To clarify, I have a function white_text that takes in a string and the coordinates on the screen, then draws the screen at the appointed place. I need to pass along a string to it, not a bunch of chars.

ThatOneDude02
04-03-2005, 05:26 PM
http://blog.syrsan.com/index.php?p=18

tkups
04-03-2005, 05:29 PM
http://blog.syrsan.com/index.php?p=18

Yay! I shall test this at once

$1.25
04-03-2005, 05:29 PM
your not adding the string variable.

GreggBrain
04-03-2005, 05:30 PM
:emmy:

tkups
04-03-2005, 05:32 PM
your not adding the string variable.

What?

And as for the testing:

aggregate ` std::ostringstream os' has incomplete type and cannot be defined :emo:

ThatOneDude02
04-03-2005, 05:37 PM
What?

And as for the testing:

aggregate ` std::ostringstream os' has incomplete type and cannot be defined :emo:
#include <sstream> ?

You've outgrown me TKP. I haven't given you tip that's worked in months.

tkups
04-03-2005, 05:39 PM
#include &lt;sstream&gt; ?

You've outgrown me TKP. I haven't given you tip that's worked in months.

Well it doesn;t seem to be an include error, because it says incomplete, which idnicates that it recognizes it, but as part of a larger command. I'll try that, though.

$1.25
04-03-2005, 05:39 PM
youre not adding the string variable, which is why youre not retaining the numerals.

tkups
04-03-2005, 05:39 PM
Well, I was wrong TODO, that fixed it. <3

tkups
04-03-2005, 05:40 PM
youre not adding the string variable, which is why youre not retaining the numerals.

I still don't know what this means, but my problem has been solved.

$1.25
04-03-2005, 05:42 PM
nigger, i fixed your problem not tod.

ThatOneDude02
04-03-2005, 05:42 PM
Well, I was wrong TODO, that fixed it. <3I had to cheat and ask the internet to redeem myself.

zethon
08-25-2005, 03:55 PM
itoa