Return integers from vector intersection.
hey guys, I am trying to return integers from a vector intersection I set up to give me the number of matching elements in two strings.
that works, now what I want to do is also return the actual integers that matched.
How can I take this code:
vector<string> intersection(vector<string> &v1, vector<string> &v2)
{
vector<string> v3;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
set_intersection(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v3));
return v3;
}
int match_array()
{
std::vector<string> v1 root.get<int>("user_length", 0);
std::vector<string> v2 root.get<int>("job_length", 0);
auto v3 = intersection(v1, v2);
for(string n : v3)
std::cout << n << ' ';
}
and make it also return a string or array of the matched integers.
Posted Jan 10, 2016, 6:07 PM UTC · edited
26
What integers? You're working with vectors of strings. What's
root?The string is a bunch of integers. These are all being pulled in through a REST call wich gives me JSON, I then parse it out before I do this.
Ah. So why not use vectors of ints instead? std::stoi() is the function for converting between strings and integers.
Okay, so how would I go about an implementation of this?
std::transform would be a good start.