Boost logo

Boost Users :

Subject: Re: [Boost-users] [Iterators] iterators over char *
From: Patrick Horgan (phorgan1_at_[hidden])
Date: 2010-11-04 03:28:41


On 11/01/2010 09:46 PM, Rao, Anant wrote:


Thanks Krzysztof, Patrick!

You're welcome.

 

While it’s true that a char* seems to be equivalent to an iterator (in this case)

In all cases.  An iterator models pointer behavior.  Pointers were the first iterators.  A char* is a random access iterator so can be used also anywhere you would need a bidirectional, forward, output, or input iterator.

, I prefer the iterator/reverse_iterator much better. For example, if I use an iterator and it reaches end(), I can do

--it to  get to the last char.

 

In a char * model, once I reach the NULL ptr (at the end of the string), I can’t back-trackn.

That's not true.  You can do the same thing. (I assume you mean the null terminator, '\0' rather than null pointer.)  Just do --ptr to get to the last char.

Patrick

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