Andreas Zoglauer wrote:
>
> Hi Andre,
>
> Thanks, your solution works.
>
> If I get you right, you think this is a bug in libc.
Actually, I was wrong. strstream is not a part of libc but seems
to be in libstdc++.
I think this is not really a 'bug' (maybe a 'feature'). If I do info
iostream,
then "Files and Strings" -> "Strings" then I find an entry:
- Method: char* ostrstream::str ()
A pointer to the string managed by this `ostrstream'. Implies
`ostrstream::freeze()'.
Note that if you want the string to be nul-terminated, you must
do
that yourself (perhaps by writing ends to the stream).
So we have been warned :)
On the other hand, the examples on ostringstream (note that this is
not exactly ostrstream) in Stroustroup's "C++ programming
language third edition" in chapter 21.5.3, I never see << '\0' or <<
ends.
> Have you any idea why this problem never appeared in ROOT versions below
> 3.00.04?
No.
> I use the strstream class VERY frequently in my programs and the
> problem never appeared.
In the worst case, you might consider writing your own ostrstream
class..
Looking at my /usr/include/g++/strstream.h, it looks like
char *str() is unfortunately not declared virtual but I guess
you can easily copy the following and modify the str() function.
I would give this class a different name from ostrstream.
class ostrstream : public strstreambase, public ostream {
public:
ostrstream() { }
ostrstream(char *cp, int n, int mode=ios::out)
:strstreambase(cp,n,mode){}
_IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
char *str() { return ((strstreambuf*)_strbuf)->str(); }
void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
};
best regards,
André
--
------------------+----------------------------------
Andre Holzner | +41 22 76 76750
Bureau 32 2-C13 | Building 32
CERN | Office 2-C13
CH-1211 Geneve 23 | http://wwweth.cern.ch/~holzner/
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET