Use two traversal methods to delete the intersection of two STD: vector.
Today we use find (); and erase (); of vector ();
After a while, I thought it was necessary to remember even simple things.
Prevent the next time. # Include <vector>
# Include <string>
# Include <algorithm>
Using namespace STD;
Int main ()
{
Vector <string> vstr1;
Vstr1.push _ back ("001 ");
Vstr1.push _ back ("002 ");
Vstr1.push _ back ("003 ");
Vector <string> vstr2;
Vstr2.push _ back ("001 ");
Vstr2.push _ back ("002 ");
/*
For (Auto itr = vstr2.begin (); itr! = Vstr2.end (); ++ itr)
{
Auto itrfind = find (vstr1.begin (), vstr1.end (), * itr );
If (itrfind! = Vstr1.end ())
{
Vstr1.erase (itrfind );
}
}
*/
For (Auto itr = vstr1.begin (); itr! = Vstr1.end ();)
{
If (find (vstr2.begin (), vstr2.end (), * itr )! = Vstr2.end ())
{
Itr = vstr1.erase (itr );
}
Else
{
++ Itr;
}
}
Return 0;
}
URL: http://greatverve.cnblogs.com/archive/2013/02/23/vector-find-erase.html