Topic: Help!!: How do I zero out an ostringstream to write over it?
Author: Tim Rogstad <timothy.d.rogstad@jpl.nasa.gov>
Date: 1999/08/11 Raw View
Hi,
Can anyone help me with this one? Under an earlier compile (CW
Pro2) I was able to create one C++ object of type 'ostringstream' and
reuse it in the same scope continually by:
myOStringStream.seekp(0);
Doing so also zeroed out the string (probably not the correct thing to
do according to the standard, but it was useful to me.)
However, CW Pro5, places the insert point at the beginning of the string
but does NOT zero out the string (most likely the standard behaviour.)
I want to use the same object over and over in the particular scope
because there are so many things I have to do (i.e. multiple objects
would avoid the problem, but the construction would kill
performance...there are a lot of strings and it's in an intensive
real-time program.)
How do I do this?
Thanks,
Tim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Robert Klemme <klemme@unity.de>
Date: 1999/08/11 Raw View
Tim Rogstad schrieb:
> However, CW Pro5, places the insert point at the beginning of the strin=
g
> but does NOT zero out the string (most likely the standard behaviour.)
yes, i think so. at least, it should be. however, you can do this:
myOStringStream.str(string());
myOStringStream.clear(); // clear error flags
> I want to use the same object over and over in the particular scope
> because there are so many things I have to do (i.e. multiple objects
> would avoid the problem, but the construction would kill
> performance...there are a lot of strings and it's in an intensive
> real-time program.)
well, performance could be an issue with my suggestion because there
are strings created. just give it a try.
regards
robert
-- =
Robert Klemme
Internet Consultant/Berater
-------------------------------------------------------------
UNITY AG ~ Riemekestra=DFe 160 ~ D-33106 Paderborn
http://www.unity.de ~ E-Mail: mailto:klemme@unity.de
Telefon: 0 52 51 / 6 90 90-207 ~ Fax: 0 52 51 / 6 90 90-199
-------------------------------------------------------------
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: anders@milkweed.com (Anders Pytte)
Date: 1999/08/11 Raw View
Looks like the best way is as follows:
myOStringStream.str(constEmptyString);
assuming you have defined something like:
static const string constEmptyString;
or you could just us a literal:
myOStringStream.str("");
These will also reset the position so you don't need to call seekp(0).
Anders.
In article <37B08AC0.7ECA10C2@jpl.nasa.gov>, Tim Rogstad
<timothy.d.rogstad@jpl.nasa.gov> wrote:
>Hi,
> Can anyone help me with this one? Under an earlier compile (CW
>Pro2) I was able to create one C++ object of type 'ostringstream' and
>reuse it in the same scope continually by:
>
> myOStringStream.seekp(0);
>
>Doing so also zeroed out the string (probably not the correct thing to
>do according to the standard, but it was useful to me.)
>
>However, CW Pro5, places the insert point at the beginning of the string
>but does NOT zero out the string (most likely the standard behaviour.)
>
>I want to use the same object over and over in the particular scope
>because there are so many things I have to do (i.e. multiple objects
>would avoid the problem, but the construction would kill
>performance...there are a lot of strings and it's in an intensive
>real-time program.)
>
>How do I do this?
>
>Thanks,
>Tim
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Edward Diener <eddielee@abraxis.com>
Date: 1999/08/12 Raw View
My documentation says that "myOStringStream.flush();" should do the trick.
Tim Rogstad wrote:
> Hi,
> Can anyone help me with this one? Under an earlier compile (CW
> Pro2) I was able to create one C++ object of type 'ostringstream' and
> reuse it in the same scope continually by:
>
> myOStringStream.seekp(0);
>
> Doing so also zeroed out the string (probably not the correct thing to
> do according to the standard, but it was useful to me.)
>
> However, CW Pro5, places the insert point at the beginning of the string
> but does NOT zero out the string (most likely the standard behaviour.)
>
> I want to use the same object over and over in the particular scope
> because there are so many things I have to do (i.e. multiple objects
> would avoid the problem, but the construction would kill
> performance...there are a lot of strings and it's in an intensive
> real-time program.)
>
> How do I do this?
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@uiuc.edu (Siemel B. Naran)
Date: 1999/08/12 Raw View
On 11 Aug 1999 18:33:32 GMT, Robert Klemme <klemme@unity.de> wrote:
>myOStringStream.str(string());
>myOStringStream.clear(); // clear error flags
One should clear the error flags before resetting the str, otherwise it
is possible for the resetting of the str to have no effect.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]