| View previous topic :: View next topic |
| Author |
Message |
Icos Grandmaster Cheater
Reputation: 0
Joined: 12 May 2007 Posts: 524
|
Posted: Mon Jun 18, 2007 7:09 pm Post subject: How do I convert a number into string with C++? |
|
|
As title. I know that I can use the old C functions itoa() or sprintf() to accomplish that, but are there any other built-in functions in C++ that can perform the same job?
Thanks in advance. |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Jun 18, 2007 7:10 pm Post subject: |
|
|
| nope |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jun 18, 2007 7:11 pm Post subject: |
|
|
What exactly do you mean by making a number into a string? You mean get its ascii character? That would be typecasting and you would do this.
| Code: |
#include <iostream>
using namespace std;
int main()
{
for (int x = 0; x < 256; x++) {
cout<< x<<". "<< (char)x <<" ";
}
cin.get();
}
|
Otherwise I don't exactly get what your saying. If you could give me and example it would be nice. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Icos Grandmaster Cheater
Reputation: 0
Joined: 12 May 2007 Posts: 524
|
Posted: Mon Jun 18, 2007 7:12 pm Post subject: |
|
|
So I must stick to the old C functions to perform that? |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jun 18, 2007 7:13 pm Post subject: |
|
|
I don't even understand you unless you mean typecasting. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Jun 18, 2007 7:14 pm Post subject: |
|
|
| oib111 wrote: | | What exactly do you mean by making a number into a string? You mean get its ascii character? That would be typecasting and you would do this. |
he means turning 12345 into "12345"- the only way to do that is with a big table with the digits and their ascii representations, and loop through every character in the string you want to fill, filling it up. that is itoa. |
|
| Back to top |
|
 |
Icos Grandmaster Cheater
Reputation: 0
Joined: 12 May 2007 Posts: 524
|
Posted: Mon Jun 18, 2007 7:18 pm Post subject: |
|
|
| Thanks appal. It has cleared things up much better. |
|
| Back to top |
|
 |
|