Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 14th, 2005, 7:00 PM   #1
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
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!
uman is offline   Reply With Quote
Old Feb 14th, 2005, 8:22 PM   #2
stephen7
Newbie
 
Join Date: Feb 2005
Posts: 1
Rep Power: 0 stephen7 is on a distinguished road
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;
}
stephen7 is offline   Reply With Quote
Old Feb 14th, 2005, 9:09 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Originally Posted by uman
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!
Are you looking for itoa()?
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 14th, 2005, 9:40 PM   #4
Encryption
Programmer
 
Encryption's Avatar
 
Join Date: Feb 2005
Posts: 42
Rep Power: 0 Encryption is on a distinguished road
Send a message via AIM to Encryption Send a message via MSN to Encryption Send a message via Yahoo to Encryption
I haven't even checked, and didn't understand the question too well, but would type casting work?
__________________
Quote:
Originally Posted by Bjarne Stroustrup
* "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do succeed, you will blow away your whole leg."

* "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone."
Encryption is offline   Reply With Quote
Old Feb 15th, 2005, 7:32 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Nope. He's definitely looking for itoa.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 15th, 2005, 4:07 PM   #6
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
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....
Cipher is offline   Reply With Quote
Old Feb 15th, 2005, 8:22 PM   #7
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Ah, thanks. itoa is exactly what I was looking for. You guys are, as always, indispensible!
uman is offline   Reply With Quote
Old Feb 16th, 2005, 7:59 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Don't forget the semicolons, Cipher.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 16th, 2005, 9:06 AM   #9
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
ahhh..HATE THE SEMICOLONS!

I always forget them...

ahh.ahh.zzzzzzzzzzz
__________________
And there was much rejoicing... Yay....
Cipher is offline   Reply With Quote
Old Feb 16th, 2005, 4:11 PM   #10
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
bleh u beat me too it...

forgot your "return 0;" also...
__________________
...
Xero is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC