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
Conversion Functions Conversion functions are member functions used for the following purposes: 1. Conversion of object to basic data type. 2. Conversion of basic data ty

C Program for FUNCTION OF FIND THE FACTORIAL float factorial(float); void main() {           float i=0,c=0;           clrscr();           printf("ENTER THE DIGI

A: No. If they're utilized properly, they increase encapsulation. You frequently require splitting a class in half while the two halves will have distinct numbers of instances o

Ba s i c r u l e s o f C + + p r o g r a m : ·     I t m u s t h a v e o n l y o n e m a i n f u n c ti o n ·

It is a feature in C++ to reduce name collisions in the global name space. This namespace keyword assigns a separate name to a library that allows other libraries to use the simila

Explain Processing A Data File? Mainly data file applications needs that a data file be altered as it is being processed. For instance in an application involving the processin

Aim: To implement a program to convert time in 24 hour format to 12 hour format. Code:                       #include #include #include class time24 {

Define How Passing Arrays to a Function? A complete array can be passed to a function as an argument. The manner in which the array is passed be different from that of an ordin

code for solving optimal solution for matrix