The obvious solution is to use a new stringstream every time, for example:
for (...) { std::stringstream ss; for (...) {
This is the stringstream way stringstream was designed to be used. (Also: do you really want stringstream , or just ostringstream ?)
source share