[lug] C++ libraries in Linux

Keith Brown kbrown8 at uswest.net
Tue Sep 18 10:10:12 MDT 2001


Hi,

I believe you have memory leak in your example.  Once you do buf.str(), the
program owns the *char that is returned, unless it tells strstream otherwise,
which I forget how to do.  I believe you need to do it like:

char * s = buf.str();
rtnval = s;
delete [] s;
return rtnval;

Keith

"Scott A. Herod" wrote:

> Hi,
>   I use something like the following:
>
> #include
> <strstream>
> string paraNode::toString()
> {
>     string rtnval;
>     strstream buf;
>
>     buf << "Paragraph: "
>         << ATTR_ALIGN << " = " << _align << ", "
>         << ATTR_WRAP_MODE << " = " << _mode
>         << ends;
>
>     rtnval = buf.str();
>     return rtnval;
> }
>
> > Can it be true?  There are no converters to go from an int to a string?  Or
> > a double to a string?
> >
> > --Keith
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

--
Keith Brown
12640 Xavier St
Broomfield, CO 80020
303.438.8169





More information about the LUG mailing list