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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:55:48+00:00 2026-05-27T04:55:48+00:00

VC++ 2010 Lets say I have the following: struct person { char * name;

  • 0

VC++ 2010

Lets say I have the following:

struct person {
    char *  name;
    int     age;
};

Then I have a vector which holds these:

std::vector <person> person_list;

Now, after pushing back a few of these elements, how can I locate one based off of one of its properties? Best case scenario, I would like it to return a pointer to the vectors element 'where name = string' type of deal.

  • 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-27T04:55:48+00:00Added an answer on May 27, 2026 at 4:55 am

    One suggestion to improve. Use std::string instead of char*. You have to #include <string> for that.

    • In C++11 you can use lamda and std::find_if as:

      #include <algorithm>
      
      auto it = std::find_if(persons.begin(), persons.end(), [](const person & p)
                                  {
                                       return p.name = "string"; 
                                  });
      
    • In C++03, you can use functor as predicate:

      #include <algorithm>
      
      struct name_predicate
      {
          std::string name;
          name_predicate(std::string const & name) : name(name) {}
          bool operator()(person const & p) { return name == p.name; }
      };
      
      std::vector<person>::iterator it = std::find_if(persons.begin(), 
                                                      persons.end(),
                                                      name_predicate("string"));
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a date in the following format: 2010-12-11 (year-mon-day) With PHP,
Let's say I have the following table: Employee name start_date end_date John 2009-10-10 2009-12-31
Lets say I have an intraweb application (written in Delphi 2010) with an iwEdit
Let's say we have the following Student.mdd: person=not null ptr general.Person interests=set general.ActivityField education=set
Lets say I have two tables table_1 ID Name Status 1 John 2 Peter
I have 2 dates. Lets say they look like this. $start = 2010/12/24; $end
Lets say we have 5 tables Fact_2011 Fact_2010 Fact_2009 Fact_2008 Fact_2007 each of which
Lets say, i have the following table | start | end | activity +---------------------+---------------------+---------
Let's say I have the following tables tableA seq datea 1 2010-01-01 2 2010-02-01
Year 2010 and we still have to write boilerplate codes. Lets assume we are

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.