Vector of Structs

Ok, so let's say I have a struct made up of 4 elements and then I send a series of these structs to a vector and now I want to loop the vector through to print out each element of the struct individually. Is this possible? I was writing a function for this earlier and ran into a snag, does anyone have any ideas? Any help would, as always, be greatly appreciated. Below is the struct I've created as well as the function that prints the vector (the structs have already been written into the vector at this point).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
struct file
{
    string num;
    string name;
    float cost;
    int markup;
};

void printItems(vector<file> items)
{
    int spot = 0;
    float markAmt = 0.0;
    float price = 0.0;
    for(int count = 0; count < items.size(); count++)
    {
        cout << "Item number: " << items.item.num[count] << endl;
        cout << "Item name: " << items.item.name[count] << endl;
        cout << "Item cost: " << items.item.cost[count] << endl;
        cout << "Item markup: ";
        for(int mult = 1; (mult * 5) == 50; mult ++)
        {
            if((mult * 5) == items.item.markup[count])
            {
                spot = mult;
                cout << "** " << items.item.markup[count] << "%\t$ ";
                markAmt = items.item.cost[count] * (items.item.markup[count] * DECI);
                price = items.item.cost[count] + markAmt;
                cout << markAmt << "\t$ " << price << " **" << endl;
            }
            else
            {
                cout << "   " << (mult * 5) << "%\t$ ";
                markAmt = items.item.cost[count] * ((mult * 5) * DECI);
                price = items.item.cost[count] + markAmt;
                cout << markAmt << "\t$ " << price << endl;
            }
        }
        cout << "There is/are " << spot - 1 << " report(s) above the indicated markup," << endl;
        cout << "and " << 10 - spot << " below it." << endl << endl;
    }
    cout << "The total number of reports processed is: " << items.size();
}
And that snag is?

In any case:
for(int mult = 1; (mult * 5) == 50; mult ++)
mult*5 is 5 and 5!=50, so the loop body will never run. I don't know what you're trying to do, but I doubt this was intended.
You're right about that, thanks for pointing it out but the snag is that I can't get this function to compile, because I don't know if it's possible to access just one element of a struct within a vector like I'm trying to do throughout it.
Is the format I'm using correct? For example, would cout << items.item.cost[count] print the cost element of the item struct of the count index? Or do I have to do it some other way, or is it even possible at all?
Oh, I see my problem now, my index is in the wrong spot instead of items.item.cost[count], it should really be items[count].cost, but thanks again for pointing out that other detail.
Topic archived. No new replies allowed.