I have solved it by my own. Here it is :
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <iterator>
using namespace std;
struct Person
{
string Name;
string ID;
};
class mainClass
{
private :
vector <Person> Vector;
public :
mainClass() { }
void storeVector();
void displayVector();
void findID();
void removeID();
friend ostream & operator << (ostream &, const Person &);
};
struct IDnumber : public binary_function <Person, string, bool>
{
bool operator () ( const Person &Obj, const string &ID ) const
{
return (Obj.ID == ID);
}
};
ostream & operator << (ostream &stream, const Person &Obj)
{
return stream << " Name : " << Obj.Name << ", ID : " << Obj.ID;
}
void mainClass :: storeVector()
{
Person Obj1;
Obj1.Name = "Tapas";
Obj1.ID = "1";
Vector.push_back(Obj1);
Person Obj2;
Obj2.Name = "Ashok";
Obj2.ID = "2";
Vector.push_back(Obj2);
Person Obj3;
Obj3.Name = "Arnab";
Obj3.ID = "3";
Vector.push_back(Obj3);
Person Obj4;
Obj4.Name = "Sayantan";
Obj4.ID = "4";
Vector.push_back(Obj4);
Person Obj5;
Obj5.Name = "Mrinal";
Obj5.ID = "5";
Vector.push_back(Obj5);
}
void mainClass :: displayVector()
{
copy(Vector.begin(), Vector.end(), ostream_iterator <Person> (cout, "\n"));
}
void mainClass :: findID()
{
string ID;
cout << endl;
cout << " Enter the ID to find : ";
cin >> ID;
vector <Person> :: iterator it;
it = find_if(Vector.begin(), Vector.end(), bind2nd(IDnumber(), ID));
if (it != Vector.end())
{
cout << " Specified ID found." << endl;
cout << " Name : " << it->Name << ", ID : " << it->ID << endl;
}
else
{
cout << " Specified ID not found." << endl;
}
}
void mainClass :: removeID()
{
string ID;
cout << endl;
cout << " Enter the ID to remove : ";
cin >> ID;
vector <Person> :: iterator it;
it = find_if(Vector.begin(), Vector.end(), bind2nd(IDnumber(), ID));
if (it != Vector.end())
{
cout << " Specified ID found." << endl;
cout << " Name : " << it->Name << ", ID : " << it->ID << endl;
Vector.erase(it);
cout << " Data successfully deleted." << endl << endl;
}
else
{
cout << " Specified ID not found." << endl;
}
}
int main()
{
mainClass Obj;
Obj.storeVector();
Obj.displayVector();
Obj.findID();
Obj.removeID();
Obj.displayVector();
return 0;
}