#include <iostream>
using namespace std;
int main()
{
struct Car
{
char maked[20];
int year;
};
unsigned int i;
cout << "How many cars do you wish to catalog ? ";
cin >> i;
Car *car = new Car[i];
for (int k = 0; k < i; k++)
{
cout << "Car #" << k + 1 << ":" << endl;
cout << "Please enter the make : ";
cin.getline(car[k].maked,20);
//cin.get();
cout << "Please enter the year made: ";
//cin.get();
cin>> car[k].year;
cin.get();
}
cout << "Here is your collection : " << endl;
for (int k = 0; k < i; k++)
{
cout << car[k].year << "\t" << car[k].maked << endl;
}
delete[]car;
return 0;
}
为什么for循环内的第一次不让输入字符串啊?