intersection between vector c++

#include <algorithm> //std::sort
#include <iostream> //std::cout
#include <string> //std::string
#include <vector> //std::vector

std::vector<std::string> intersection(std::vector<std::string> &v1,
                                      std::vector<std::string> &v2){
    std::vector<std::string> v3;

    std::sort(v1.begin(), v1.end());
    std::sort(v2.begin(), v2.end());

    std::set_intersection(v1.begin(),v1.end(),
                          v2.begin(),v2.end(),
                          back_inserter(v3));
    return v3;
}

int main(){
    std::vector<std::string> v1 {"a","b","c"};
    std::vector<std::string> v2 {"b","c"};

    auto v3 = intersection(v1, v2);

    for(std::string n : v3)
        std::cout << n << ' ';
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
intersection of two vector stl intersection of two vectors in c++ intersection of two arrays in c++ using vector intersection of vector and line intersection vectors c++ intersection between 6 different vectors c++ multiset intersection c++ vector intersection c++ use sort before set intersection c++ intersection of two arrays c++ intersection of two vectors in cpp c++ set intersection two vectors set intersection function c++ set intersection in c++ vector intersection calculator find intersection between vectors c++ std intersection c++ c++ intersection of two sets c++ set intersection take intersection of two sets c++ cpp two set intersection example calculate intersection of two vectors c++ intersection between vectors c++ stl set_intersection c++ multiset intersection cpp set intersection cpp 2 set intersection c++ std::vector intersection with another vector c++ c++ intersection intersection set c++ string example intersection of vectors c++ intersection of two vectors c++ how to find intersection of 2 vectors c++ cpp intersection of two vectors vector set_intersection c++ c++ check intersection of two vectors how to find intersection of two vectors c++ intersection of two sets in c++ how to find the intersection of two sets in c++ set intersection c++ vector string intersection c++ c++ intersection of two vectors intersection of two vectors cpp intersection set c++ intersect cpp set_intersection c++ intersection of sets in c++ intersection in c++ intersection of 2 sets in c++ intersection of two sets cpp vector intersection with c++ set intersection c++ intersection betwin vectors c++ get overlap of set c++ set intersection in cpp size of intersection vectors c++ intersection vector c++ find intersection of 2 vectors in C++ intersection between vecto c++ intersection between vector c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source