stringstream ss;
ss.width(3);
ss << setfill('0');

you can write it before loop.

to clear stringtream use str( "" ) method: ss.str( "" );