Solved

int to string

Posted on 1998-11-24
5
316 Views
Last Modified: 2010-04-01
I want to know how to convert an integer to string.
such as 123456 to "123456".
0
Comment
Question by:yyzz
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
guruprasad031298 earned 200 total points
ID: 1178581
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
 
LVL 2

Expert Comment

by:rayb
ID: 1178582
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
 

Author Comment

by:yyzz
ID: 1178583
How to do it with c++? Does stdlib.h include it?
0
 
LVL 1

Expert Comment

by:guruprasad031298
ID: 1178584
yeah. you need to include <stdlib.h> in your source code to do that.
0
 

Author Comment

by:yyzz
ID: 1178585
thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now