Is there a way to get a int into a string, so I can use it as a string? I tried typecasting... lol that didint work, any ideas?
Thanks!
Printable View
Is there a way to get a int into a string, so I can use it as a string? I tried typecasting... lol that didint work, any ideas?
Thanks!
just a word of caution:Quote:
Originally posted by jon_nc17
Is there a way to get a int into a string, so I can use it as a string? I tried typecasting... lol that didint work, any ideas?
Thanks!
c++ doesn't natively support strings. it only deals directly with numbers. if your string looks something like this:you have a pointer address. typecasting will give you that address and convert it to int form.PHP Code:
char* temp = "wpeokwpokerpow";
if your string looks like this:
then casting might work. but casting there could be an overloaded operator function, designed for that.PHP Code:
string temp = "wpeokwpokerpow";
sigh... can someone check if the stl string class does this?
can't you just do the thing manually?
this may have some errors since I didn't test it
// if you want to include the sign (example: '+' or '-'), you need to change the array to type char. otherwise, the sign will be lost because I can't think of another way.Code:...
int number,x,copy=0;
cin>>number;
copy=number;
for(x=0;copy!=0;x++)
{
copy/=10;
x++;
}
int *array = new int[x];
copy=number;
for(x=0;x<array.strlen();x++)
{
array[x]=copy%10;
copy%=10;
}
...