| re: clearing contents of ostringstream object
"Maxim Yegorushkin" <firstname.lastname@gmail.com> wrote in message[color=blue]
>
> Do not forget to reset flags. The complete clear is:
>
> oss.str("");
> oss.clear();
>[/color]
From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears
str("") does not clear the stream bits. It seems to me that in clearing the
internal buffer, one would intend that the stream bits would also be reset
(in a good state). Is there a reason this is not the defined behavior?
Aside from a slight performance hit, I have not been able to think of a
situation where it would be beneficial to set the internal buffer to an
empty string (in essence resetting it), but leave the state of the stream
unchanged. If performance is the reason, then under what conditions will an
ostringstream enter a "bad" state (needing to be clear()'ed)?
If I'm just doing stuff like this, is there ever a need to clear():
// contrived example
ostringstream oss;
for (int i = 0; i < 50; ++i)
{
oss << "File:" << i;
cout << oss.str() << endl;
oss.str("");
}
Thanks,
Kyle |