First of all, let's understand what you are doing.
struct Apartment{
int number;
string owner;
string condition;
}ap;
Firstly, you create an Apartement struct which have the name "ap".
cout << "Enter the apartment number: " << endl;
cin >> ap.number;
cout << "Enter the name of the owner: " << endl;
cin >> ap.owner;
cout << "Enter the condition: " << endl;
cin >> ap.condition;
Secondly, (I assume that you are in your main function) you are asking the user to enter some information. You have to keep in mind that cin only that the first word and stop at the first whitespace it sees if you plan to save more word, you should use getline. See this link for more information : http://www.cplusplus.com/doc/tutorial/basic_io/
apartment building[50] = { ap.number, ap.owner, ap.condition};
Finally, your last line will crash for two reasons. Firstly, because the type apartment does not exist. I believe you meant to write Apartment. Secondly because you cannot create an array like this. I suggest you to look at this: http://www.cplusplus.com/doc/tutorial/arrays/
I am not sure exactly what you want to do, so I will give you a sample of code that ask a user how many apartment he has and ask the information for the number of apartment he owns.
struct Apartment{
int number;
string owner;
string condition;
};
int main() {
cout << "Hello, how many apartment do you own?";
int nbAppt = 0;
cin >> nbAppt;
Apartment appt[nbAppt];
for(int i = 0; i < nbAppt; i++) {
cout << "Appartment number " << i << endl;
cout << "Enter the apartment number: ";
cin >> appt[i].number;
cout << "Enter the name of the owner: ";
cin >> appt[i].owner;
cout << "Enter the condition: " << endl;
cin >> appt[i].condition;
}
}
Ps: Please note that I assumed that you included namespace std;
Ps2: I did not include any relevant include.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…