qq_43370828 2019-07-05 14:38 采纳率: 0%
浏览 535
已采纳

小白一枚。。。用getline遇到换行符就直接跳过了。。。求高人指点

#include
using namespace std;
struct car
{
string manu;
int birth_day;
};
int main()
{
cout<<"How many cars do you wish to catalog? ";
int number;
cin>>number;
car pc=new car[number+1];
int i;
for(i=0;i<number;i++)
{
cout<<"Car #"<<i+1<<":"<<endl
<<"Please enter the make: ";
getline(cin,(
(pc+i)).manu);
cout<<"Please enter the year made: " ;
cin>>(*(pc+i)).birth_day;
}
cout<<"Here is your collection:"<<endl;
for(int j=0;j<i;j++)
{
cout<<(*(pc+j)).birth_day<<" "
<<(*(pc+j)).manu<<endl;
}
}
图片说明

  • 写回答

1条回答 默认 最新

  • qtchen_1988 2019-07-05 15:05
    关注
     在getline(cin,(*(pc+i)).manu); 之前加 getchar();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?