-
Vector of Structures
Before main i create a structure:
Code:
struct numberinfo
{
int number;
int AoN;
};
Then i create my vector of type structure:
Code:
vector <numberinfo> Numinfo;
And when i do things like this:
Numinfo.AoN.push_back(amount);
It says:
52 C:\CODE\CS192.cpp 'class std::vector<numberinfo, std::allocator<numberinfo> >' has no member named 'number'
i have no idea why it is doing this can some one help :confused:
-
You push back elements onto the vector through push_back, so something like:
Code:
numberinfo test;
Numinfo.push_back(test);
// Accesss first element
Numinfo[0].number = 100;
// Bounds checking direct access (slower perhaps)
Numinfo.at(0).number = 100;
// Or, safer perhaps is to use iterators
for(vector<numberinfo>::iterator iter = Numinfo.begin(); iter != Numinfo.end(); ++iter)
{
(*iter).number = 50;
}
-
Thanks alot man that really helped
-
Those operations seem to be illegal becouse when i run my program with calls like that is crashes