By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,645 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,645 IT Pros & Developers. It's quick & easy.

clearing a stringstream

P: n/a
Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();

thanks
Feb 23 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
s5n
On Feb 23, 8:26 pm, Gary Wessle <phd...@yahoo.comwrote:
Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();
For an ostringstream, try os.str("");

Feb 23 '07 #2

P: n/a
Gary Wessle wrote:
Hi

how can I clear a stringstream?
ss.clear();
or
ss.flush();
Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

HTH,
- J.
Feb 23 '07 #3

P: n/a
Jacek Dziedzic <ja************************@gmail.comwrites:
Gary Wessle wrote:
Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
Feb 23 '07 #4

P: n/a
Gary Wessle wrote:
Jacek Dziedzic <ja************************@gmail.comwrites:

>>Gary Wessle wrote:
>>>Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.

yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
ss.str("");

But I think it's generally better to start with a new stringstream
rather than try to reuse an old one.

Why not post some code?

john
Feb 23 '07 #5

P: n/a
Gary Wessle wrote:
Jacek Dziedzic <ja************************@gmail.comwrites:
>Gary Wessle wrote:
>>Hi
how can I clear a stringstream?
ss.clear(); or ss.flush();

Depends what you mean by 'clear'. To clear the state
(error flags, etc.) use ss.clear(). This does not clear
the contents of the stringstream, however. In particular,
if you are trying to read data from a stringstream and
fail because of some leftover characters, clear()ing the
stringstream only clears the error flags, leaving the
leftover characters still in the stringstream.


yes, I want to clear the content of the stringstream and not the flag.
how can I do this?
You've been already told: ss.str("")

Don't you have TFM you can R?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.