Hi guys.
Can anyone give me a rough idea of how to remove duplicate items from a vector?
Hi guys.
Can anyone give me a rough idea of how to remove duplicate items from a vector?
Use a std::set instead of a std::vector.
There's also an std::unique() function that does just what you're looking for (I believe you'd need to also use the std::vector::erase() function afterwards).
Last edited by cpjust; 03-07-2010 at 08:59 PM.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
If your vector is sorted, or if sorting it is an option, then indeed std::unique with the range version of member function erase() would be a very good option.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)