0

I need to get the intersection of two vectors such that:

vector<int> a{1 2 3 4 5 6 7 8};
vector<int> b{2 4 6 8 10 12};

result should be:

vector<int> c{2 4 6 8}

How can i do this?

chopper
  • 6,649
  • 7
  • 36
  • 53
filipe
  • 13
  • 3
  • 1
    Is that a `std::vector` or an OpenCV-specific type? If it's a `std::vector` and your elements are sorted look at doing `#include ` and [std::merge](http://www.cplusplus.com/reference/algorithm/merge/). – HostileFork says dont trust SE Oct 28 '14 at 00:26
  • 1
    check [this][1] post which how to use intersection of vector [1]: http://stackoverflow.com/questions/19483663/vector-intersection-in-c –  Oct 28 '14 at 01:58
  • It's better to use std::set take a look here: http://www.cplusplus.com/reference/algorithm/set_intersection/ – Andrey Smorodov Oct 28 '14 at 14:45

0 Answers0