flushing has no meaning for stringstream, as there is no external device that it sends data to.
Based on your use case, you want to empty the stringstream, that's done by calling str("")
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <sstream>
usingnamespace std;
int main()
{
stringstream x;
x << "abc";
x.str("");
x << "def";
// cout << x << endl; // this will not print the strnig either way
cout << x.str() << '\n'; // it's either .str()
cout << x.rdbuf() << '\n'; // or rdbuf()
}