Erase an element in vector

I want to erase a data in an element of a vector.

Attributes in the vector are name, id, salary.

Let's say I just want to delete the data in salary, making it null while the rest data in name and id are still there. Can anyone tell me how to do that? Is it possible?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class employee{
 string name;
 int id;
 double salary;
public:
 employee(string name, int id, double salary) : name(name), id(id), salary(salary) {}
 string getName()   {return name;}
 int getID()        {return id;}
 double getSalary()    {return salary;}
};

int main(){
    vector<employee> employees;
    employees.push_back(employee("John", 117, 30000));
    cout << employees[0].getName() <<" "<< employees[0].getID() <<" "<< employees[0].getSalary()<<endl;
    employees.erase (employees.begin());
}
You can erase an element of a vector. However it seems you are asking about deleting a member of the class employee, which doesn't make sense.

What you would need to do is add some method to the class, to modify the data of that employee object.
Is it possible?

Yes.

Can anyone tell me how to do that?

You'll need to write a function that sets the salary to some value.
Topic archived. No new replies allowed.