Sign in to follow this  
pikapika

cout number of elementsbetween two iterators

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
thankyou very much!! may ask where you found this function i could not find it on

http://cppreference.com/all_cpp_functions.html

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

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