int to string

I want to know how to convert an integer to string.
such as 123456 to "123456".
Who is Participating?
guruprasad031298Connect With a Mentor Commented:
Looks pretty simple to me.

Use _itoa function to convert the integer to ASCII text. You might want to use _itot if you are working with 32-bit OS like Windows 95 or NT.

May be you would like to use ltoa (for long to ASCII), if you are working with one of the low-end OSs, as the size of the int is small in these systems and you need to use the above said value as long or unsigned int.
The conversion functions that guruprasad points out do work well.  Here's an alternative:

  char buffer[64];
  sprintf( buffer, "%ld", 123456 );

If using MFC, you could also use the CString::Format method.

yyzzAuthor Commented:
How to do it with c++? Does stdlib.h include it?
yeah. you need to include <stdlib.h> in your source code to do that.
yyzzAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.