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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:54:46+00:00 2026-06-18T08:54:46+00:00

I am using C++ and i have 2 vectors that a related to each

  • 0

I am using C++ and i have 2 vectors that a related to each other:

vector<double> val = {.3,.5,.2,.4};
vector<string> str = {'a','b','c','d'};

I would like to search val for the max, and then return the string from str in the same position:

vector<double>::const_iterator it;
it = max_element(val.begin(), val.end());

So, how can i use it inside str to get the letter?

string lettter;
letter = str.at(it-> ????? );

Thank!!!

  • 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-18T08:54:48+00:00Added an answer on June 18, 2026 at 8:54 am

    You can find out how far it is from the beginning of val and then use that to index str:

    str[std::distance(std::begin(val), it)]
    

    By using std::distance, this will still work if you change the type of val to a container whose iterator does not provide random access. However, when using it on a random access iterator, you will still get constant time complexity. Using std::begin allows you to change val to an C-style array if you ever wanted to.

    It’s worth mentioning that you should be initialising str with:

    vector<string> str = {"a","b","c","d"};
    

    std::string has no constructor that takes a char.

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

Sidebar

Related Questions

I have multiple vectors of varying lengths that I would like to plot next
I have a plug-in vector established using System.AddIn that accepts the body of a
I have a program that draws some vector graphics using System.Drawing and the Graphics
I have a vector drawing app where users can draw lines using multiple quadratic
I have the following code: #include <iostream> #include <vector> using namespace std; struct A{};
I have three classes that I am using and have shortened for ease of
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have been using TortoiseSVN for some time and I really like it. I
I have a map that relates integers to vectors (of objects). These vectors represent
I find myself using C++11 more and more lately, and where I would have

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.