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 219 views
1 answer 185 views
1 answer 192 views
192 views asked Jan 13, 2023 by avibootz
1 answer 255 views
255 views asked Jan 24, 2021 by avibootz
1 answer 235 views
...