Boost logo

Boost Users :

Subject: Re: [Boost-users] Reading a file in reverse using boost::iostreams
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2019-02-13 04:43:39

My solution would be:

1. memory map the file (either use boost.interprocess or trivially
hand-roll a few OS calls)
2. build an iterator pair (i.e. char *) representing the extent of the
mapped memory,
3. call std::make_reverse_iterator on the iterator pair
4. use a standard algorithm

On Wed, 13 Feb 2019 at 06:09, Gavin Lambert via Boost-users <
boost-users_at_[hidden]> wrote:

> On 13/02/2019 05:33, Sean Farrow wrote:
> > Is there an easy way to read a file in reverse using boost::iostreams?
> >
> > I’ve got a case where I need to detect whether text is present and it’s
> > closer to the end of the file than the beginning.
> You should be able to read the length of the stream, then seek to a
> position near the end and read forwards from there.
> Of course, you need to know a suitable value to use as the range where
> you expect the value to be present; if you get this wrong then you'll
> either have a false negative or you'll waste a bit more time jumping
> back further and trying again.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Richard Hodges
office: +442032898513
home: +376841522
mobile: +376380212

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at