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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:52:37+00:00 2026-05-20T07:52:37+00:00

I would appreciate some advice related to manipulating data in vectors. I have written

  • 0

I would appreciate some advice related to manipulating data in vectors.

I have written code that results in two sets of vectors: strings (labels/names) and doubles (data). The order of the labels in the string vector may be different for each calculation I do.

Here’s what I would like to do. Let’s say that one element (label) in the vector is: Tom. I would like to know if it is possible to search the string/label vector for “Tom” and return the index of Tom’s location in the vector.

Is this something that sounds possible in C++? I would appreciate any tips. Thanks.

  • 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-20T07:52:37+00:00Added an answer on May 20, 2026 at 7:52 am

    Use std::find

    vector<string>::iterator it = std::find(vec.begin(), vec.end(), "Tom");
    if (it == vec.end()) 
        return -1;
    else
        return it - vec.begin();
    

    A better solution would be to pick a more suitable container, such as the mentioned std::map

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

Sidebar

Related Questions

I have a crash and would greatly appreciate some advice on how to find
I have some code that was written by me some time ago, anyway I
I would appreciate some help with something I working on and have not done
I have a problem finding references to this subject and would appreciate some help.
I would appreciate some advice on how to structure a database for the following
I don't want to reinvent the wheel here so would really appreciate some advice!
I would appreciate some advice on the best method of managing multiple SQL connections
I am working on a comment system in Codeigniter and would appreciate some advice
I would like to get some advice. I am developing a system that will
I have an interesting problem which I've been looking into and would appreciate some

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.