I have tried to use the max function but it needs a iterator and that are A.begin and A.end but for my program I want to find for a range say from i to x .I tried to read the docs but was unable to find the solution. Any help would be appreciated.Thank you.
1 Answer
You're not looking for max. But for std::max_element.
To use it:
std::vector<int> v; // fill it auto max_it = std::max_element(v.begin()+i, v.end()); And to check in the range [i,j):
auto max_it = std::max_element(v.begin()+i, v.begin()+j); max_it here is an iterator, to get the number from it:
int max_number = *max_it;
items.begin() + i