Sign in to follow this  

cout number of elementsbetween two iterators

This topic is 4138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

cout number of elements between two iterators i have cit = unique(mcit->begin(),mcit->end(),cmpeqrank); and now i want to count between mcit->begin() and cit to see how many unique elements there are. i tried the stl template functions count_if and count but they count only elements which are equal to a result when i just want to count all elements.

Share this post


Link to post
Share on other sites
Hi
you can use count_if with an unary predicate the always returns true, this should could all elements in the range [beg,end)

Edit: You should use Mc Cloud's method, and if you are using random access iterators you can simply subtract them just as you can it with pointers.

Share this post


Link to post
Share on other sites
There s an excellent book about the STL:
The C++ Standard Library: A Tutorial and Reference
by Nicolai M.Josuttis
ISBN:0-201-37926-0
$59.99

Its worth the money

Share this post


Link to post
Share on other sites

This topic is 4138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this