Empty a stringstream...

F

Francesco

Ciao,
I've this problem...
#include <iostream>
#include <stdlib.h>
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
stringstream s;
s << " questa e' una prova " << endl;
cout << s.str();
s << " ma non so se funziona" << endl;
cout << s.str();
system("PAUSE");
return 0;
}
The output si ...
questa e' una prova
questa e' una prova
ma non so se funziona
Premere un tasto per continuare...

But I want...
questa e' una prova
ma non so se funziona
Premere un tasto per continuare...


How may I delete the old value in the stream and use the stringstream in
rewrite mode and not in append?
Grazie mille,
Checco.
 
R

Rolf Magnus

Francesco said:
Ciao,
I've this problem...
#include <iostream>
#include <stdlib.h>
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
stringstream s;
s << " questa e' una prova " << endl;
cout << s.str();
s << " ma non so se funziona" << endl;
cout << s.str();
system("PAUSE");
return 0;
}
The output si ...
questa e' una prova
questa e' una prova
ma non so se funziona
Premere un tasto per continuare...

But I want...
questa e' una prova
ma non so se funziona
Premere un tasto per continuare...


How may I delete the old value in the stream and use the stringstream
in rewrite mode and not in append?

There is no such thing as "rewrite mode". How would the stream know as
which points you want them to erase their content? You can however
empty them explicitly by doing:

s.str("");
 
F

Francesco

There is no such thing as "rewrite mode". How would the stream know as
which points you want them to erase their content? You can however
empty them explicitly by doing:

s.str("");

Thanks... it's exactly what I need.

Thanks again,
Checco.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top