How to empty stringstream and reset the stringstream to a default constructed state in C++

1 Answer

0 votes
#include <iostream>  
#include <sstream>  

int main() {  
    int n = 840192;  
    
    std::stringstream ss;  
    ss << n;  

    std::cout << ss.str() << "\n";
    
    std::stringstream().swap(ss);
    
    ss << "c++";
    
    std::cout << ss.str();
      
    return 0;
}  




/*
run:

840192
c++

*/

 



answered Jan 14, 2021 by avibootz

Related questions

2 answers 217 views
1 answer 182 views
1 answer 190 views
190 views asked Jan 13, 2023 by avibootz
1 answer 251 views
251 views asked Jan 24, 2021 by avibootz
1 answer 232 views
...