Solved

int to string

Posted on 1998-11-24
5
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 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