For example:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
    int num = 10;
    string str;
    stringstream toString;
    toString << num;
    toString >> str;
    cout << str << "\n"; //10
    int num2 = 20;
    string str2;
    toString << num2;
    toString >> str2;
    cout << str2 << "\n"; //str2 is empty
    return 0;
}
I know that I must clear this like:
toString.str("");
toString.clear();
But why doesn't it clear automatically after using operator >>?
 
     
    