intersection between vector c++
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 << ' ';
}
Also in C++:
- Title
- compare function in sort c++ stl
- Category
- C++
- Title
- stoi c++
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- c++ max of array
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- c++ for loops
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- level order traversal
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- UPARAM(ref)
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- tellg and seekg c++
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- How to traverse in a tree iterative C++
- Category
- C++
- Title
- how to calculate inverse trigonometric values in c++
- Category
- C++
- Title
- how to print nth palindrome number in c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- hobo 8
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ clamp
- Category
- C++
- Title
- c++ write string
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- compile c++ linux
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- std string find character c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- how to get a letter from the user c++ string
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- double ended queue in c++ stl
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- msdn parse command line
- Category
- C++
- Title
- c++ class template
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- expected unqualified-id before 'if'
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- c++ program to find gcd of 3 numbers
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- cannot jump from switch statement to this case label c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- how to format decimal palces in c++
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- c++ excel cell blank cells
- Category
- C++
- Title
- initialize vector of pointers c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- how to use assrt c++
- Category
- C++
- Title
- cs1955 unity vector3
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- list conda environments
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- translate
- Category
- C++