How can I get the maximum or minimum value in a vector in C++?
And am I wrong in assuming it would be more or less the same with an array?
I need an iterator, right? I tried it with max_element
, but I kept getting an error.
vector<int>::const_iterator it;
it = max_element(cloud.begin(), cloud.end());
error: request for member ‘begin’ in ‘cloud’, which is of non-class type ‘int [10]’
Best Answer
Using C++11/C++0x compile flags, you can
Otherwise, write your own:
See it live at http://ideone.com/aDkhW:
Oh, and use
std::minmax_element(...)
if you need both at once :/