新手学习C++ primer plus 遇到的问题,高手指教。。
i诙谐 2011-10-16 05:21:20 #include<iostream>
#include<string>
using namespace std;
const int Max=30;
struct car
{
string make;
int year_made;
};
void main()
{
int num_car;int i=0;
cout<<" How many cars do you wish to catolog?____\b\b";
cin>>num_car;
car *c=new car [num_car];
for(i=0;i<num_car;i++)
{
cout<<"Car #"<<(i+1)<<":"<<endl;
cout<<"Please enter the make:";
getline(cin,c[i].make); //// 问题在这行
//整行输入存在错误。。要怎样修改才行a ?
//char make[]我也试过,用cin.get(c[i].make,30).get()等都不行,
cout<<"Please enter the year made:";
cin>>c[i].year_made;//cin.get(c[i].year_made,Max);
}
////////
cout<<"\n\aHere is your collection:"<<endl;
for(i=0;i<num_car;i++)
{
cout<<c[i].year_made<<" "<<c[i].make<<endl;
}
delete []c;
/////////
}