Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-05-14 11:55:50


AMDG

Dan Smithers wrote:
> boost::sregex_iterator it(sm[1].str().begin(), sm[1].str().end(),
> handles);
>

str() returns a std::string by *value* Thus, the two iterators point
into different string objects.

> I get a segmentation fault if I run this - sometimes with a memory
> exhausted notice.
>
> If I replace the iterator line
>
> boost::sregex_iterator it(sm[1].str().begin(), sm[1].str().end(), handles);
>
> with
>
> const string& hs(sm[1].str());
> boost::sregex_iterator it(hs.begin(), hs.end(), handles);
>
> then everything seems to work.
>
> What's going on here? Is there a simpler way of achieving this?
>

Now you only get one string object.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net