使用new创建一个动态结构数组

时间:2025-03-17 21:46:02
int main()
{
    int counts;
    int i;
    cout << "How many cars do you wish to catalog? ";
    cin >> counts;
    car *ps = new car [counts];
    for (i = 0; i < counts; i++)
    {
        cout << "Car #" << i + 1 << " :" << endl;
        cout << "Please enter the make: ";
        ();
        (ps[i].name, 20);
        cout << "Please enter the year made: ";
        cin >> ps[i].year;
        ();
    }
    cout << "Here is your collection: " << endl;
    for (i = 0; i < counts; i++)
    {
        cout << ps[i].year << "  " << ps[i].name << endl;
        
    }
    delete[] ps;
    
    system("pause");
    return 0;
}

相关文章