Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Int to String

Status
Not open for further replies.

Alderian

Programmer
Joined
Apr 25, 2003
Messages
1
Location
SE
I usually do programs in Java but I decided to try Visual c++ 6.0 for awhile. But id like to know how to convert a int, double, float and so on to a string.
 
sprintf

A veryversatile string formatting function.
 
Or std::stringstream, a more versatile and more type-safe string formatting class.

Or boost::lexical_cast, a convenient wrapper around that use of stringstream, which can be found at
 
why not use atoi for short integers long and for floating point values use atof?

example
char str[] = "tek tips";
double x = atof(str);
int y = atoi(str);
 
CString str;
str.Format("%i", IntVar);
or
str.Format("%lf", DoubleVar);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top