cout number of elementsbetween two iterators

Started by
3 comments, last by Basiror 17 years, 8 months ago
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.
Advertisement
std::distance

CM
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.
http://www.8ung.at/basiror/theironcross.html
thankyou very much!! may ask where you found this function i could not find it on

http://cppreference.com/all_cpp_functions.html
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
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement