Trying to sort out and remove duplicates from a char* vector.
Sorting working but the duplicates are still there.
Code:
#include <iostream> // cout
#include <algorithm> // unique, distance
#include <string>
#include <iterator> // std::back_inserter
#include <set>
#include <vector> // vector
using namespace std;
bool strcmpFunc(const char *c1, const char *c2)
{
return strcmp(c1, c2) < 0;
}
char *url[]=
{
"bbbb",
"bbbb",
"aaa",
"ccccccc",
"a",
"aaa"
};
int main ()
{
vector <char*> v;
vector<char*>::iterator it;
int size = sizeof(url)/sizeof(url[0]);
for (int i=0; i< size; ++i)
v.push_back(url[i]);
cout << v.size() <<'\n';
sort(v.begin(), v.end(), strcmpFunc);
v.erase(std::unique(v.begin(), v.end()), v.end());
cout << "vector after sorting:\n\n";
for (it=v.begin(); it!=v.end(); ++it)
cout << *it << '\n';
cout << '\n';
return 0;
}