#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
struct CAR
{
string name;
int per_year;
};
int main()
{
int num;
cout << "How many cars do you wish to catalog? ";
cin >> num;
cin.get();
//CAR *ps = new CAR[num];A
CAR car[10];
//cin >> (s_car[0]).name;
//delete[] s_car;
for (int i = 0; i < num; i++)
{
cout << "Car #" << i+1<<endl;
cout << "Please enter the make:";
getline(cin,car[1].name);
cout << "Please enter the year made: ";
cin >> car[i].per_year;
cin.get();
};
cout << "Here is your collection: " << endl;
for (int i = 0;i<num;i++)
{
cout << car[i].per_year << " " << car[i].name << endl;
}
cout << "Done. " << endl;
return 0;
}
结果:
问题:为什么第一个里面没有输入的q,解决不了这个bug