How do i change an integer to a string?, C/C++ Programming

A: The simplest way is to use a stringstream:




using namespace std;

string itos(int i) // convert int to string


stringstream s;

s << i;

return s.str();


int main()


int i = 127;

string ss = itos(i);

const char* p = ss.c_str();

cout << ss << " " << p << "\n";


Naturally, this technique works for converting any type that you can output using << to a string.



Posted Date: 3/20/2013 3:37:49 AM | Location : United States

Related Discussions:- How do i change an integer to a string?, Assignment Help, Ask Question on How do i change an integer to a string?, Get Answer, Expert's Help, How do i change an integer to a string? Discussions

Write discussion on How do i change an integer to a string?
Your posts are moderated
Related Questions
I want source code for class booking system by using C++ Programming...Urgent

You are going to write a function that computes the total interest charged on a credit card before it is paid off. List all the inputs the function will need.

Add words in Dictionary: void Dictionary::add( Object& objectToAdd ) {     if( !objectToAdd.isAssociation() )         ClassLib_error( __ENOTASSOC );     else

implementation of the power and factorial in programs

- But with less features and more user-friendly (particularly for non-tech savvy users). - Software needed having a left menu with links (no pictures required) for every hardwar

the problem description. The order of the C Program should be as follows: Variables and constants Use #define statements to define the constants. Use arr

Command-line arguments are passed into programs using the arguments of main(). Here's a quick example, for a program called by typing "progname file.txt 1 2.7": #include #incl

how we can code in c++ for assignment problem (operation research) method to mkinimization and mamization

A string is said to be "Beautiful"€, if it contains only non repetitive alphabets

In order to override a method, a subclass of the class which originally declared the method have to declare a method along with the same name, return type (or a subclass of that re