//C++primer plus 第五章 编程联系 第六题 设计一个名为car的结构.....(数字与字母混合输入)

include

include

using namespace std;
struct car
{
/* data */
string maker;
int year;
};

int main()
{
int n;
cout << "How many cars do you wish to catalog?" << endl;
(cin >> n).get();

car *p = new car [n];
for (int i = 0; i < n; i++)
{

    cout << "Car #" << i+1 << "\n";
    cout << "Please enter the make: " <<'\n';

    getline(cin,p[i].maker);
    //p[i].maker =  cin.get();
    //cin.ignore(4,'\n');
    //cin.clear();
    cout << "Please enter the year made: " <<endl;
    (cin >> p[i].year).get();
}
cout << "Here is your collection:" << endl;

  for (int i = 0; i < n; i++)
{

    cout <<p[i].year<<" "<<p[i].maker<<endl;

}
delete [] p;
return 0;

}
//为什么字母输入一行用 p[i].maker = cin.get();cin.get();就会产生输入问题,只保存第一个字母后面的就略掉了