什麼是創建動態(不知道這是否是正確的單詞)對象的最佳方式?例如,如果我運行以下命令:創建新的「動態」對象?
Person man[10];
cout << "MENU" << endl;
cout << "1. Add a person to the list" << endl;
cout << "2. Delete a person from the list" << endl;
cout << "3. Change a person's information'" << endl;
cout << "4. Locate a person by ID number" << endl;
cout << "5. Locate a person by last name" << endl;
cout << "6. Print the list on the screen" << endl;
cout << "7. Load the list from a file" << endl;
cout << "8. Save the list to a file" << endl;
cout << "9. Exit the program" << endl;
cin >> a;
if (a == 1) {
if (i <= 10) {
Person man[i];
cout << "Please enter your last name: " ;
cin >> last;
man[i].setLastName(last);
i++;
cout << man[i].getLastName();
}
}
當我運行這一點,我可以進入我的姓,但是當我按ENTER鍵程序停止運行。這是什麼原因,並有沒有更好的方式來創建這些對象「配置文件」?
謝謝,如果這是一個愚蠢的問題,我很抱歉。
'Person man [10];' - 您已經創建了10個'Person'對象。查找'std :: vector'。 – PaulMcKenzie