Page 1 of 1
How could I convert a Long Long Int into string?
Posted: Wed Apr 30, 2003 4:20 am
by BestIvan
i can convert a int by itoa()
i can convert a long by ltoa()
but how about long long?
Posted: Wed Apr 30, 2003 4:54 am
by kmhasan
So far as i know, itoa and ltoa are not ANSI compliant.
I use sprintf(str,"%d",num) for int, and sprintf(str,"%lld",num) for long long int. Here str is the string, and num is the integer variable.
Posted: Wed Apr 30, 2003 5:47 pm
by ChristopherH
Alternatively, you can use an ostringstream for all kinds of output formatting, including long long.
[cpp]
#include <sstream>
string longlongtostring(long long x) {
ostringstream os;
os << x;
return os.str();
}
[/cpp]
Posted: Wed Apr 30, 2003 6:14 pm
by kmhasan
Cool.
Didn't know how to do it in C++. Thanks.
Posted: Wed Jun 18, 2003 5:00 pm
by anupam
well i think sprintf is the best way to do all the converts to string..
right?