Here my code:
#include<iostream>
#include<string.h>
#define SIZE 100
struct person{
std::string name;
int age;
};
void entry(struct person *info){
std::getline(std::cin, info->name);
std::cin >> info->age;
}
int main(int argc, char const *argv[]) {
struct person roster[SIZE];
int n; // number of people in the roster:
std::cin >> n;
for (int i = 0; i < n; i++){
entry(&roster[i]);
}
return 0;
}
I am learning how to use "struct" in c++ and in this program, I created a roster includes name and age, but the program crashed whenever I try to read the string "name". Can you help me? Thank you, I stuck at this for days.
P.s: I am learning c++ with a C-book, so my code might contain C-ism.