int to string from sstream..


hi.
I have this member function of a simple class, which receives definitely lower than the set limit values ​​for type 'int'.
the problem consists in the fact that the stringstream not make the transition from the int type, to the type string.

in fact, if you try to print to video, the content of m3x, the result is as empty.

any suggestions, before it burns my pc? :)

thanks in advance.
1
2
3
4
5
6
7
8
9
10

  string convert_int_to_str( int c )            
	{
		stringstream assign_int ( c );
		string m3x;
		assign_int.str( m3x );
		cout << " test ---- c: " << c << " m3x: " << m3x << endl;
		return m3x;
	}
1
2
3
4
5
6
std::string intToString(int i) {
	std::stringstream stream;
	stream << i;
	return stream.str();
}
	
If your compiler supports C++11 you can use std::to_string(int) http://www.cplusplus.com/reference/string/to_string/
Thanks guys.

I try this and after i reply.
Se you.
Thx naraku. Work :)
Last edited on
Topic archived. No new replies allowed.