Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Empty a stringstream...

Reply
Thread Tools

Empty a stringstream...

 
 
Francesco
Guest
Posts: n/a
 
      03-01-2004
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.
 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      03-01-2004
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("");

 
Reply With Quote
 
 
 
 
Francesco
Guest
Posts: n/a
 
      03-01-2004
On Mon, 01 Mar 2004 12:03:01 +0100, Rolf Magnus <>
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.
 
Reply With Quote
 
prakasha prakasha is offline
Junior Member
Join Date: Mar 2011
Posts: 2
 
      03-22-2011
Thanks alot.... Rolf Magnus
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView ASP Control and an empty field not an empty record. ButlerDJIAM ASP .Net 0 11-09-2006 06:40 PM
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
empty lists vs empty generators Brian Roberts Python 12 05-04-2005 08:59 PM
Check if a directory is empty and empty it Marcia Hon C Programming 8 02-14-2004 03:53 AM
empty/non-empty element John XML 1 07-16-2003 10:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57