![]() |
Int to String
How do I turn an in into a string in C++?
|
Try this function to convert from int to std::string.
:
#include <sstream>/Klarre |
You can use atoi(string s) if it is available on your system.
|
Klarre has a good answer, but consider this: suppose you have the absolute value of 10 (decimal, the average number of fingers on two hands, assuming you don't mess around carelessly with a table saw). What is a string representing that? "10"? "Ten"? "diez"? "umpty-zillion"? You are in an area of (hopefully, somewhat cooperative) representation. There is no hard and fast answer.
|
Quote:
|
make sure its in the ascii range, or what ever system your using. look for the bounds.
|
Just to be helpful (and to learn it myself), I though I'd devise the reverse function. :)
:
#include <string> |
Well what i want is a loop that will turn the index number of that for loop into the string... ex. 10 = "10" not "Ten"
|
Slightly-off-topic alert: This is not 100% C++, but it is an intresting function that I came across yesterday:
:
#include <iostream> I wish it was that easy in C++. |
is that C prm753?
|
| All times are GMT -5. The time now is 8:07 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC