Is there a way to convert from an integer to a string?

Is there a way to convert from an integer to a string?

Yes, one way of doing it is ...

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
	int x = 123;

	stringstream ss;
	string s;

	ss << x;
	ss >> s;

	cout << s;

	return 0;
}
commented: Perfect!!! +1

Yes, one way of doing it is ...

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
	int x = 123;

	stringstream ss;
	string s;

	ss << x;
	ss >> s;

	cout << s;

	return 0;
}

That worked perfectly, thanks!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.