好吧我搜索的問題,但無法得到我的答案,或沒有使用適當的術語。C++我如何直接通過程序自動創建對象
if(choice == 2){
string tempName, tempAddress; int tempNic,tempContact;
cout << "\n\t\t*\tWelcome to Our Sponsor Registeration Section\t*\n\n";
cout << "Please enter your name : "; cin>>tempName;
cout << "Please enter your National Identity Card Number : "; cin>>tempNic;
cout << "Please enter your Contact Number : "; cin>>tempContact;
cout << "Please enter your Address : "; cin>>tempAddress;
// prototype Sponsor(string n, string add, int nic_n, int phone) constructor
Sponsor (Constructor goes here) // how to make many objects now?
}
代碼粘貼在這裏https://codeshare.io/aVxl42
檢測線69我要去的地方使用構造函數添加值,這個我可以加1個對象,但我怎麼辦這樣,如果使用程序的人想要添加更多的對象嗎?
我知道我需要封裝61和70之間的東西。 請幫我解決這個問題。
請將*相關*代碼直接包含在問題主體中。如果我們應該閱讀特殊文字,請用例如註釋。想想如果鏈接消失會發生什麼,這將使問題完全沒有價值。請[請閱讀如何提出良好問題](http://stackoverflow.com/help/how-to-ask),並學習如何創建[最小,完整和可驗證示例](http:// stackoverflow。 COM /幫助/ MCVE)。 –
我不太清楚你想做什麼,但列表(http://www.cplusplus.com/reference/list/list/)或矢量(http://www.cplusplus.com/reference/vector/vector/vector /)可能會有所幫助。 – Lehue
將用戶輸入請求置於循環中,並將創建的贊助者添加到向量中。 – DrPepperJo