#include<iostream>
#include<ctime>
using namespace std;
struct Car
{
char name[500];
int year;
};
int main()
{
int num;
//int ch;
cout << "how many cars do you wish to catalog?";
cin >> num;
//ch=cin.get();
//cout << ch << endl;
//while (cin.get() != '\n');
Car *car = new Car[num];
for (int i = 0; i < num; i++)
{
cout << "Car #" << i + 1 << ":" << endl;
cout << "please enter the make: ";
cin.get(car[i].name,500);
//cin.get();
//cin.getline(car[i].name, 500).get();
cout << "please enter the year made: ";
cin >> car[i].year;
//cin.get();
//while (cin.get() != '\n');
}
cout << "hear is you collection: " << endl;
for (int i = 0; i < num; i++)
cout << car[i].year << " " << car[i].name << endl;
delete[]car;
return 0;
}
以上注释是问题的解决方案,使用cin.get()就可以解决问题,我会用,但是我不知道原理以及为什么出错