How can I save the value of min_element? It says it’s a forward iterator but I can’t seem to figure out how to save (assign to a variable to) it. I want to be able to access it by location in the vector. All I can find is examples of using the actual element (using *min_element() ). I tried
iterator< forward_iterator_tag, vector<string> > min_word_iterator = min_element(first_words_in_subvecs.begin(), first_words_in_subvecs.end());
but that didn’t work. I’m going to replace the element at that index with a different element.
You can use the distance provided by stl to find the position.
You need to pass the iterator returned by min_element to it to get the position
See this example code