Copy Code

for (auto it = v2.begin (); it != v2.end (); it++) { auto fit = std::find (v1.begin (), v1.end (), *it); if (fit != v1.end ()) { std::cout << "Element " << *fit << " found at position : "; std::cout << fit - v2.begin() << " (counting from zero) \n" ; } else { std::cout << "Element not found.\n\n"; remove(v2.begin(), v2.end(), *fit); } } return

if (fit != v2.end ())

{

std::cout << "Element " << *fit << " found at position : ";

std::cout << fit - v2.begin() << " (counting from zero) \n" ;

}

else

{

v2.erase(fit);

}

But, its not working.

~~See my (partial) solution below.~~Forget that, the solution provided by CPallini is the perfect answer.