ow do I make a struct of variables/values that can be saved in an array like fashion? Meaning I want to make 10 records of the struct below for example of 10 people's hair color, eye color and age. Do I make an array of struct objects?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
struct foo
{
int age;
int eye_color;
int hair_color;
};
int main()
{
Foo foo
//set a record
foo.age = 45;
foo.eye_color = hazel;
foo.hair_color = brown;
//make 10 new foo records...how to
}
Then use MyFooData.push_back or emplace_back to put a foo into your vector.
push_back pushes an already created obj onto the vector, while emplace_back constructs a foo obj at the end of the vector. So this means foo needs to have a constructor.
1 2
foo.eye_color = hazel;
foo.hair_color = brown;
int is perhaps not a good type for these, did you mean std::string ?