URGENTT HELPPP

Whats the simplest way to convert from int to string?

THANKS
closed account (D80DSL3A)
Using a stringstream object?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<string>
#include <sstream>
using namespace std;

int main(void)
{	
	int i = 12345;// the integer
	stringstream ss;
	string istr;// the string
	ss << i;// stream integer into stringstream object
	ss >> istr;// stream back into string
	cout << istr;// test output
        cout << endl;
	return 0;
}

This works but I'm not sure it's the simplest possible way.
EDIT: horance89 has a better idea. I forgot about itoa(). Athars solution may be simplest of all but I haven't used boost yet.
Last edited on
Last edited on
There's a simpler way:

string str=boost::lexical_cast<string>(12345);
Topic archived. No new replies allowed.