> It's okay to use the result of .c_str() as long as the string object
> stays in scope, and none of the non-const member functions are
> called. Here, I think the problem is that TermIterator's overloaded
> operator*() returns a string object within the if block's scope, and it
> goes immediately out of scope. You could check this by adding
Right, I overlooked that TermIterator creates temporary string (if I
understand you correctly).
>
> string s = *i;
>
> in function scope, and replacing (*i) with s in the if block. This might
> also be more obvious than the presented patch, but I think the patch is
> fine too.
I would prefer my change as it avoids creating another std::string. At
least I think.
Thank you
--
Vlad