lundi 17 janvier 2022

How to take input after string variable? [duplicate]

struct book {
  int bookid;
  string bookname;
  float prize;
};
     

int main(){
        book b1;
        cout<<"Enter bookid"<<" "<<"Enter bookname"<<" "<<"enter prize"<<endl;
        cin>>b1.bookid;
        getline(cin,b1.bookname);
        cin>>b1.prize;
        cout<<b1.bookid<< " "<<b1.bookname<<" "<<b1.prize<<endl;
        return 0;
}

But after taking book name, it skips taking prize and direct show output.

Aucun commentaire:

Enregistrer un commentaire