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

  • Home
  • SEARCH
  • 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 9130065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:53:21+00:00 2026-06-17T07:53:21+00:00

I have a list with all the elements as struct of form typedef struct

  • 0

I have a list with all the elements as struct of form

typedef struct person_node{
    string name;
    string country;
}person;

std::list<person> list;

The list is already sorted on person name.

How do I use the inbuilt binary_search() function in this?

I already know how to use this binary_search() on a list with only numbers as data, but I wonder how can I use it for such a list.

I am using this binary function as:

binary_search (list.begin(), list.end(), value, compare_function);

Only thing I don’t know is, “What should I enter in place of value, if I need to look for a specific name in the list?”

Also I want an iterator to point to that node, if found.

  • 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-17T07:53:22+00:00Added an answer on June 17, 2026 at 7:53 am

    You enter a person containing the name you want to find.

    Also note that binary_search is only rarely useful (it only tells you whether the item is present, not where it is in the collection. It is doubly useless on a std::list, because it requires random-access iterators to work at all well (which std::list doesn’t provide).

    So, what you probably want is an std::vector<person> or std::deque<person>, which you’ll probably want to search with std::lower_bound or std::upper_bound. std::lower_bound and std::upper_bound will each return an iterator to the item they found, giving you access to that object.

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

Sidebar

Related Questions

Lets say I have a following structures in c++ struct Fruit { std::string name,
I have a large list [[1,.., ..],[2,...,...],[5,...,...],[1,...,...]] I need to remove all elements that
I have a List<List<String>> I need to get a List of all possible concatenation
So i have my definition of the list as a global variable: typedef struct
I have a list of all theme elements stored as a theme that is
If I have List<String> text how can I create a sub-list of all continious
I have a linked list like this: typedef struct _LIST_ELEMENT { T* data; _LIST_ELEMENT*
I have to search through a list and replace all occurrences of one element
I have a PhoneGap app, where I need to list all the user's friends,
In my directory I have subfolders, and I want to list all directories like

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.