Line 42: You're calling human.put() inside push_back(). push_back is expecting a Person object. human.put returns a void. You can't do a push_back() of a void.
39 40 41 42 43
vector <Person> array;
for(int i=0; i<10; i++)
{ human.put(); // Get the data
array.push_back(human);
}
Or as an alternative, you could change put to return a reference.
15 16 17 18 19 20
Person & put ()
{ ...
return *this;
}
...
array.push_back(human.put());
As I worked with your program I came up with these questions:
Do you have to use a C style character array for "name" and "nationality"? Could you use a "std::string"?
Is "name" and "nationality" comprised of a single word or could it contain a space? Your formatted input would stop at the first space and what is stored in these variables would not be correct. Using some form of "getline()" would be a better choice for these two variables. Also a "std::string" would help.
Check the spelling of "nationality". You have it spelled two different ways in your program. Neither of which I believe is the correct spelling.
Do you really need an "unsigned int" for "height" and "weight"? And are these values in English or metric? Your entry may contain a decimal number, but any type of "int" will only store the whole number and drop the decimal part. Also calculations may not come out right using "int"s.
This may fix your problem, but still may not be the best way of ysing what you have.
Please don't use methods to get C-strings that don't limit the number characters they will accept into the C-string. The extraction operator is very dangerous when working with C-strings, and don't forget it doesn't allow whitespace characters.
A better alternative is to use getline(), or use the setw() manipulator prior to the C-string.
edit:
However probably the best alternative is to use std::string instead of the error prone C-strings.