struct bio{
string name;
string job;
int age;
string address;
char gender;
string hobby;
};
void delbio()
{
ofstream fout;
ifstream fin;
string kot;
char a,b;
fin.open("1.txt");
fout.open ("1.txt", ofstream::out | std::ofstream::app);
bio arrays;
arrays.name="hack";
/*part that gets record from another file*/
while (arrays.name.length()>0)
{
getline (fin,arrays.name);
if (arrays.name.length()<=0)
{
break;
}
getline (fin,arrays.job);
fin >> arrays.age;
fin >> a;
getline (fin,arrays.address);
arrays.address=a+arrays.address;
fin >> arrays.gender;
fin >> b;
getline (fin,arrays.hobby);
arrays.hobby=b+arrays.hobby;
getline(fin,kot);
newones.push_back(arrays);
}
//the part that deletes record(vector)
string str1;
cout << "Enter name and surname (Both with first letter in capital)" << endl;
cin >> str1;
int x=0;
while (x<newones.size())
{
if(newones[x].name==str1)
{
newones.erase(x,1); /*here my compiler says it is an error "no matching function for call to std::vector<bio>.erase(int&,int)"*/
}
cin.get();
x++;
}
}
The erase function expects an iterator to the element that you want to delete. You can use the begin function to get an iterator to the first element and then add x to that iterator to get an iterator to the element at position x.