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

Assignment Help:

A: The simplest way is to use a stringstream:

#include

#include

#include

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.

 

 


Related Discussions:- How do i change an integer to a string?

Padovan string , write a program that counts the number of occurences of th...

write a program that counts the number of occurences of the string in the n-th Padovan string P(n) program in java // aakash , suraj , prem sasi kumar kamaraj college progr

What operators can or cannot be overloaded?, A: Mostly can be overloaded. T...

A: Mostly can be overloaded. The only C operators which can't be are. and?: (and sizeof, that is technically an operator). C++ adds a few of its own operators, mostly which can be

Recursive function, Binomial coefficients are the numeric factors of the pr...

Binomial coefficients are the numeric factors of the products in a power of a binomial such as (x + y)n. For example, (x + y)2 = x2 + 2 x y + y2 has the coefficients 1 2 1. Binomia

Add words in dictionary - c++ program, Add words in Dictionary: void D...

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

Write a program that calculates circumference and area, Write a program cal...

Write a program called A1Q3, that reads it the radius of a circle as an integer and prints the circle's diameter, circumference and area.  Use a constant value for pi.  Do all calc

C program for string address, C Program for STRING ADDRESS #include std...

C Program for STRING ADDRESS #include stdio.h> #include conio.h> #include string.h> void main() {           char *name;           int length;           cha

Should my class declare a friend function or member function, A: Use a memb...

A: Use a member while you can and a friend when you need to. Sometimes friends are better syntactically (e.g., in class Fred, friend functions let the Fred parameter to be secon

Arrays, #question.Write a c++ program to accept and print a 1_d array

#question.Write a c++ program to accept and print a 1_d array

Virtual destructor, What about Virtual Destructor? describe it.

What about Virtual Destructor? describe it.

C program to reverse the elements of array, C program to reverse the elemen...

C program to reverse the elements of array: #define rows 3 #define cols 3 void main() {                 int i=0,j=0;                 int arr[rows][cols];

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd