[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

int to string

I want to know how to convert an integer to string.
such as 123456 to "123456".
0
yyzz
Asked:
yyzz
  • 2
  • 2
1 Solution
 
guruprasad031298Commented:
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.
0
 
raybCommented:
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.

0
 
yyzzAuthor Commented:
How to do it with c++? Does stdlib.h include it?
0
 
guruprasad031298Commented:
yeah. you need to include <stdlib.h> in your source code to do that.
0
 
yyzzAuthor Commented:
thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now