struct car
{
string name;
int year;
};
int main() {
int noOfCars;
cout<<"enter no_ of cars : ";
cin>>noOfCars;
car* cars = new car[noOfCars];
for(int i=0;i<noOfCars;i++)
{
cout<<"Car #"<<i<<endl;
cout<<"Name : ";
getline(cin,(cars[i].name)); //here is the problem
cout<<"\n year : ";
cin>>cars[i].year;
cout<<endl;
}
}
strcutの名前への文字列入力として行全体を取得することで何かが失敗しましたが、何も取得せず、直接年に進みます...:S ???
それはcinで動作しますが、私は全体の行を取りたいです!グローバルに定義された文字列では機能しますが、構造体内では機能しません