#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class A
{
public :
void getData(vector< A > &);
void putData(vector< A > &);
private :
int x;
char name[90];
};
vector< A > v;
void A :: getData(vector< A > &Aref)
{
cout << "id = ";
cin >> x;
cout << "\nname = ";
cin >> name;
}
void A :: putData(vector< A > &Aref)
{
cout << "size of vector is " << Aref.size() << endl;
for(int i=0; i < Aref.size(); i++)
cout << Aref[i].x << " : " << Aref[i].name << endl;
cin.ignore(numeric_limits< streamsize >::max(), '\n');
cin.get();
}
int main()
{
for(int i=0; i < 3; i++)
{
v.push_back(A());
v[0].getData(v);
v[0].putData(v);
}
vector< A >::iterator beg = v.begin(), en = v.end();
//v.erase( find(beg, en, v[1]) ); -->DOESN'T WORK
return 0;
}
I have used this
v.erase( find(beg, en, v[1]) ); (Line 48)
to search and delete an object from the array
vector< A > v; (A is the name of class)
Does find accepts the object as its 3rd if not what ways can a follow to delete an object.In fact I want to search the particular attribute(such as id, name) value from the array of objects and then delete that object.
please advice?