If you declare the stringstream locally inside the loop, it will always start out empty - unless you use it for several different ints within that loop. Or clear it like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <sstream>
int main()
{
int n=123, m = 456;
std::ostringstream ss;
ss << m;
std::cout << ss.str() << std::endl;
ss.str(""); // clear the stringstream
ss << n;
std::cout << ss.str() << std::endl;
}