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 6218783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:40:08+00:00 2026-05-24T07:40:08+00:00

Currently, I can only do ranged based loops with this: for (auto& value :

  • 0

Currently, I can only do ranged based loops with this:

for (auto& value : values)

But sometimes I need an iterator to the value, instead of a reference (For whatever reason). Is there any method without having to go through the whole vector comparing values?

  • 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-24T07:40:09+00:00Added an answer on May 24, 2026 at 7:40 am

    Use the old for loop as:

    for (auto it = values.begin(); it != values.end();  ++it )
    {
           auto & value = *it;
           //...
    }
    

    With this, you’ve value as well as iterator it. Use whatever you want to use.


    EDIT:

    Although I wouldn’t recommended this, but if you want to use range-based for loop (yeah, For whatever reason :D), then you can do this:

     auto it = std::begin(values); //std::begin is a free function in C++11
     for (auto& value : values)
     {
         //Use value or it - whatever you need!
         //...
         ++it; //at the end OR make sure you do this in each iteration
     }
    

    This approach avoids searching given value, since value and it are always in sync.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently only the Table Id can be used which is meaningless as it is
I can currently use sgml-pretty-print to pretty print an xml file in emacs, but
This is actually a Mahjong-based question, but a Romme- or even Poker-based background will
Currently In my embedded linux I can not open multiple ALSA sound stream. What
How can I check the umask of a program which is currently running? [update:
How can I send keyboard input messages to either the currently selected window or
I currently have a site where different users can login, and depending on their
how can I check if a user (not the one currently logged in) is
I currently have a web site where users can select a custom theme. After
Currently I have a web application where a user can use dropdown lists to

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.