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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:24:40+00:00 2026-06-15T12:24:40+00:00

Trying to define a find function for my vector because the vector holds multiple

  • 0

Trying to define a find function for my vector because the vector holds multiple data; it’s a vector of a struct

I’m taking input of an ID, and am trying to search that in my Table and find its index (if that ID already exists)

So I have the declarations here:

vector<Employee> Table;
vector<Employee>::iterator It;
vector<Employee>::iterator find_It;

//Table has these values
//Table.ID, Table.ch1, Table.ch2

And I’m trying to find the ID here:

cin >> update_ID;
find_It = find(Table.begin(), Table.end(), update_ID);

Would there be a way to do the find with the variable update_ID?

I tried doing this:

find_It = find(Table.begin(), Table.end(), (*It).update_ID;

but obviously my vector Employee doesn’t have that data member named update_ID

The other option I was thinking of doing is creating my own find function, which I’m a little confused on how to define

I want to return the index of the ID where Table.ID = update_ID

What do I put as the return type and value parameters? Is it

returntype find( Iterator, Iterator, update ID)
{ 
    for (vector<Employee>::iterator myit = Table.begin(), Table.end(), myit++)
    {
        if update_ID == Table.ID
        {
            return myit;
        }
    }
    return myit
}
  • 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-06-15T12:24:41+00:00Added an answer on June 15, 2026 at 12:24 pm

    The C++ standard library comes with a set of find functions.

    You are looking for find_if which takes a functor that specifies the comparison.

    // a functor taking the update_ID you 
    // are looking for as an argument in the constructor
    struct myfind {
      myfind(int needle) : needle(needle) {}
    
      int needle;
      bool operator()(const Employee& x) {
        return x.ID == needle;
      }
    };
    
    // use as
    int update_ID = 23;
    std::find_if(begin(Table), end(Table), myfind(update_ID));
    

    You can also use a lambda:

    int id;
    std::find_if(begin(Table), end(Table),
                 [=](const Employee& x) { return x.update_ID == id; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find a standard. The CmdLet will process data - multiple input, defined
I'm trying to define an anonymous function that calls a version of a function
I'm trying to write a function that will (1) search a given file for
I am trying to define nested modules, but I couldn't find any complete explanations
I'm trying to define a method in my vb.net interface that will only accept
I am trying to define an abstract class that has operators to compare two
I'm trying to define a very simple function in Drools as below: import java.util.List;
I'm trying to define a service endpoint in my web.config file so that I
I'm trying to define a function, factorize, which uses structural type constraints (requires static
I am currently trying to write a function that finds a value in racket

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.