Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Teach Your Child To Read

Disclosure: My content contains affiliate links.

31,647 questions

41,700 answers

573 users

How to clear ostringstream in C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <sstream>
 
using std::cout;
using std::endl;
using std::string;
 
int main()
{
    int n1 = 9023;
 
    std::ostringstream oss;
    oss << n1;
    string s = oss.str();
    cout << s << endl;

    // clear ostringstream 
    oss.str("");
    oss.clear();
    
    int n2 = 856;
    oss << n2;
    s = oss.str();
    cout << s << endl;
}
 
 
/*
run:
 
9023
856
 
*/

 

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 9 by avibootz
edited 6 days ago by avibootz

Related questions

1 answer 47 views
1 answer 65 views
65 views asked May 12, 2021 by avibootz
1 answer 54 views
54 views asked May 12, 2021 by avibootz
1 answer 80 views
80 views asked Dec 9, 2020 by avibootz
1 answer 79 views
79 views asked Jul 22, 2020 by avibootz
...