Solved

int to string

Posted on 1998-11-24
5
314 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

746 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

12 Experts available now in Live!

Get 1:1 Help Now