Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:06:30+00:00 2026-05-29T16:06:30+00:00

How can I save the value of min_element? It says it’s a forward iterator

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:06:31+00:00Added an answer on May 29, 2026 at 4:06 pm

    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

    #include <iostream>
    #include <iterator>
    #include <algorithm>
    #include <vector>
    using namespace std;
    
    int main () {
      vector<int> myvec;
      int i = 0;
      for (i=8; i>0; i--)
      {
          myvec.push_back (i*10);
      }
    
      for (i=0; i<8; i++)
      {
          cout<<"At pos :"<<i<<"|val is:"<<myvec.at(i)<<endl;
      }
    
      int min_pos = distance(myvec.begin(),min_element(myvec.begin(),myvec.end()));
      cout << "The distance is: " << min_pos << "|value is "<<*min_element(myvec.begin(),myvec.end())<<endl;
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can i save the returning value of eval function in a variable and use
In WPF, where can I save a value when in one UserControl, then later
Pre-compiled headers seem like they can save a lot of time in large projects,
In ASP.NET MVC, how can I create a single cookie and save multplie values
You can save a SQL Server 2000 DTS package as a VB .BAS file.
I can save image to iPhone (iPhone Photo Albums \ Saved Photos) with UIImageWriteToSavedPhotosAlbum(image,
Internet Explorer can save its content as an MHTML file using the Save As...
Actually I can save it in swf and in avi formats. Is there any
Opera mini browser can save HTML pages in OBML (Opera Binary Markup Language) format
Are there any Java VMs which can save their state to a file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.