make the index of the maximum : vector indexer « Vector « C++






make the index of the maximum

   
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main( )
{
   vector<int> v( 10, 66 );
   v[1] = 100;

   vector<int>::iterator before_itr = max_element( v.begin(), v.end() );
   cout << "The maximum before resizing is " << *before_itr;

   vector<int>::difference_type max_index = before_itr - v.begin();

}
  
    
    
  








Related examples in the same category

1.Use indexer to update element in the vector
2.Use toupper function to convert all elements in a char vector to upper case
3.Fill in vector with array by using pointer and offset