Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Empty a stringstream... (http://www.velocityreviews.com/forums/t281759-empty-a-stringstream.html)

Francesco 03-01-2004 10:38 AM

Empty a stringstream...
 
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.

Rolf Magnus 03-01-2004 11:03 AM

Re: Empty a stringstream...
 
Francesco wrote:

> 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("");


Francesco 03-01-2004 11:08 AM

Re: Empty a stringstream...
 
On Mon, 01 Mar 2004 12:03:01 +0100, Rolf Magnus <ramagnus@t-online.de>
wrote:

>
> 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.

prakasha 03-22-2011 04:52 AM

Thanks alot.... Rolf Magnus :)


All times are GMT. The time now is 08:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.