Can someone help me to find the location of the vector where maximum value contain. I am using visual C++.
std::vector<double> array;
Lets say:
array = {19.4 , 45.0 ,12.9 ,59.3 , 2.8 ,18.0}
The maximum value is 59.3. I want to populate its location.
max_location = 3;
Is there any way to get it…? Please help me.
Since it’s a homework, I won’t post a complete solution, just an idea. Take a look on
std::max_element(for example, here) . It returns an iterator, and if it is not equal yourarray.end()you can get a distance between it andarray.begin()which will be the index you are looking for.