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

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.

 

 

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
Question 1 Describe the theory behind class templates and function templates along with relevant programming examples Question 2 With the help of suitable programming example

implement two stacks in one array A[1...n] in such a way that neither stack overflows unless the total number of elements in both stacks together is n. For this you need to produce

write a c program to find the area under the curve4 f=(x) between x=a and x=l integrate y=(x) between the limits of a and b Solution: #include float    start_point,

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. #include float start_point,

Overall Program Objective: You will design and simulate a basic RISC processor.   You will create and encode an instruction set.  Your final task will be to "compile" a program

We started off taking about input, output, CPU and memory devices. Within C we need a method of storing large amounts of data in memory. We have used the idea of variables (pointer

i have a project in BDD(Binary Decision Diagram).. where i have to use BDD library...i m using cudd package which uses BDD technique...i download cudd package..try to run in vc++ 6

The program reads two numbers and a character (operator). If the character is "+" then sum is displayed. If it is "-"then difference is displayed. If it is "*" then product is disp

demonstrates shearing about origin

hi i want wite a C++ program that get one logical phrase (included {x,y,z,w,1,0}) and simplify it! but i ''m confused! thanxs for anubody help me...