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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:56:06+00:00 2026-05-13T21:56:06+00:00

I am trying to compare two vector objects, and return a single vector containing

  • 0

I am trying to compare two vector objects, and return a single vector containing all the chars which appear in both vectors.

How would I go about this without writing some horribly complex manual method which compares every char in the first vector to every char in the second vector and using an if to add it to a third vector (which would be returned) if they match.

Maybe my lack of real experience with vectors is making me imagine this will be harder than it really is, but I suspect there is some simplier way which I have been unable to find through searching.

  • 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-13T21:56:06+00:00Added an answer on May 13, 2026 at 9:56 pm

    I think you’re looking for std::set_intersection. The source vectors have to be sorted though. If you don’t care about the order of your output vector, you could always run it on sorted copies of your source vectors.

    And BTW, the manual naive way isn’t horribly complex. Given two source vectors s1 and s2, and a destination vector dest, you could write something that looks like this:

    for (std::vector<char>::iterator i = s1.begin(); i != s1.end(); ++i)
    {
        if (std::find(s2.begin(), s2.end(), *i) != s2.end())
        {
            dest.push_back(*i);
        }
    }
    

    You have a lot of options for the find step depending on your choice of data structure.

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

Sidebar

Related Questions

I am trying to make my code compare two vectors. Both vectors will be
I am trying to compare two tools execution time, which I have installed in
I am trying to compare two variables in which are usually strings. These variables
I am trying to compare two dates. I have this code which I thought
I'm trying to compare two arrays both 2d, I need it only match when
I am trying to compare two strings and remove any characters that appear in
When trying to compare two objects passed as arguments: first as object, second as
I am trying to compare two images to assess their registration. I would like
I am trying to compare two entries of 6 numbers, each number which can
I am trying to compare two assembly files where one was written all caps

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.