note: right after ss.str( "" ) you should call ss.clear();
unfortunately this solution is not applicable to our problem.
you should write stringstream definition and set its settigns within the loop.