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?

Explain register variable, Explain Register Variable Computers have int...

Explain Register Variable Computers have internal registers, which are used to keep data temporarily, before any operation can be performed. Intermediate results of the calcula

Algorithm, make a marksheet of 2 student with 5 subject

make a marksheet of 2 student with 5 subject

Padovan sequence, write a program that counts the number of occurrences of ...

write a program that counts the number of occurrences of the string in the n-th Padovan string P(n)

How many ways are there to initialize an int with a constant, There are two...

There are two ways for initializes in C++ as shown in the example that follows. The first way uses the traditional C notation. The second way uses constructor notation. int foo

Classes, write a grading program for a class with the following grading pol...

write a grading program for a class with the following grading polices: a.there are two quizzes eaxh graded on the basis of 10 points b.there is ome midterm exam and one final exam

Calculate and display the marks and grade for each student, In this assignm...

In this assignment you are required to develop a program that allows the creation, viewing and storage of information about ITECH7603 Students. In order to complete the task you ha

Assignment, can you tell me what is c#

can you tell me what is c#

Program is to find the area of room, Program is to find the area of room: ...

Program is to find the area of room: Program is to find the area of room with default values using classes & object class room   {   private:     int len;     i

Program to input 2 date & produce a new date - c++ program, /*  THIS PROGRA...

/*  THIS PROGRAM IS TO ASK USER TO INPUT TWO DATE & PRODUCE A NEW DATE  */ #include #include struct date  {   int dd;   int yy;   int mm;  }; date add(date d1,date d2)    {

Strings, A string S is said to be "Super ASCII", if it contains the charact...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

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