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

Ask A Question

Stats

  • Questions 509k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sorry for the long answer, but a short answer on… May 16, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer change your ImageView declaration to:: <ImageView android:id="@+id/blaimg" android:layout_width="fill_parent" android:layout_height="fill_parent"/> May 16, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer It's being interpreted once when parsing the string literal, and… May 16, 2026 at 4:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am running into trouble trying to compare and plot two files of different
I trying to compare two dates (DateTime) in nHibernate linq: query = query.Where(l =>
I have two images I'm trying to co-register - ie, one could be of
I'm trying to fetch all people without a registration for a specific event. My
So can you overload operators to handle objects in multiple classes (specifically private members.)
I'm trying to use STL to solve the following problem (I don't want to
I have two small data frames, this_tx and last_tx . They are, in every
I wanted to compare the current system date to a fix date, but get
I'm trying to applescript XCode into building and launching on device. My script is
How to compare local copy of a file with latest one in Subversion using

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.