![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
Converting integer to string ... how?
How do I convert an integer to a string? What I want is a function (if such a thing exists) that will convert for instance the integer 65 to the string "65". Sort of like the opposite of atoi(). Please help ASAP!
|
|
|
|
|
|
#2 |
|
Newbie
Join Date: Feb 2005
Posts: 1
Rep Power: 0
![]() |
Hi. Here is some codes/hints for you to start to play with:
#include <cstdlib> char* yayString(int yourNumberHere) { char *temp = new char[35]; //change size to fit your need sprintf(temp, "%d", yourNumberHere); //based on this expand more return temp; } |
|
|
|
|
|
#3 | |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Quote:
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
|
#4 | |
|
Programmer
|
I haven't even checked, and didn't understand the question too well, but would type casting work?
__________________
Quote:
|
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Nope. He's definitely looking for itoa.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
int main()
{
int a
itoa (a)
}I'm a newb to this so that might be wrong. But I think I remember reading about it in a tut.
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
Ah, thanks. itoa is exactly what I was looking for. You guys are, as always, indispensible!
|
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Don't forget the semicolons, Cipher.
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
ahhh..HATE THE SEMICOLONS!
I always forget them... ahh.ahh.zzzzzzzzzzz
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4
![]() |
bleh u beat me too it...
forgot your "return 0;" also...
__________________
... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|