mercredi 5 mai 2021

How can I delete duplicates of elements in a vector on strings?

I have a vector and I will like to remove duplicates of a string in a loop. May I please get any suggestions towards that? Thanks!

#include <vector>
#include <iostream>
#include <functional>
#include <string>

using namespace std;

struct Class {
    int x=0;
    string y="a";
};


void loopDelete(vector<Class *> &arr){
    // how do i delete duplicates of string arr.y in this vector
}

int main(){
    vector<Class *> foo;
    auto y = new Class;
    y->x = 9;
    y->y = "abc";
    foo.push_back(y);
    y->y = "bcd";
    foo.push_back(y);
    y->y = "abc";
    foo.push_back(y);
    // call loopDelete to remove duplicates of y->y?
    //loopDelete();
    cout << "size of vector at end of main is " << foo.size()<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire