Int to string

So I've got this:
outtextxy(725,k,masini[i].nr);

masini[i].nr is an integer. outtextxy is a graphics.h function.
How do I convert it to a char? Help?
Last edited on
sprintf()
or stringstream
If you've got a modern C++ compiler:

to_string(maisini[i].nr) will give you a string representation of an int.

http://www.cplusplus.com/reference/string/to_string/

I bet you're using a twenty year old C++ compiler, though.


If you want to convert an int into a char, you've got a problem; how would that work for any int that isn't zero to nine? Given that a char is a single character, what would happen to the number 10?
Last edited on
I like this implementation using std::stringstream.
http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
http://www.cplusplus.com/reference/sstream/stringstream/str/
1
2
3
4
5
6
std::string intToString(const int& num)
{
	std::stringstream ss;
	ss << num;
	return ss.str();
}
Last edited on
Topic archived. No new replies allowed.