Hi,
I would like to know how to add the objects of a vector?I wrote a code where it is adding the values to a specific object.I wanted to write a code where it can add all the values of all objects in a vector?

Recommended Answers

All 5 Replies

struct object
{
    char beer;
}temp_object;

for(int i=0; i<69; i++)
{
     temp_object.beer = value;
     my_vector.push_back(temp_object);
}

//now change it
for(int i=0, size=my_vector.size(); i<size; i++)
{
     my_vector[i].beer = another_value;
}

Hello Clinton Portis,
I didnot get u since i dont have an idea about structures.Please can u explain in detail.

vector<int> my_vector;

for(int i=0; i<69; i++)
{     
     my_vector.push_back(i);
}

//now change it
for(int i=0, size=my_vector.size(); i<size; i++)
{
     my_vector[i] *= 2;
}

Hi Clinton,
I have 3 classes:Company,Department and Employees.Company has collection of departments and each department has collection of employees.
In the department i pushed the elements:
1.HR 2.Technical
In the Employees i added names and service:
For HR DEPT i added two employees :X ,2
Y, 3
For Techincal dept added 1 employee:Z ,3

With my code i am able to get the total service of first dept(2+3=5).
Now i need to add 3 to that total service.So the total output should be(5+3=8).

I tried ur code but it is not working.

I tried ur code but it is not working.

sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.