Why it's working wrongly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why it's working wrongly?

Why it's working wrongly? https://code.sololearn.com/cDUwRaLnjIG5/?ref=app In structures cin.getline,cin.get is not working. But cin works finely.I replaced char array to string and I used getline but also that's not working why?

5th Jul 2020, 1:59 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
2 Answers
+ 1
for(int i=0;i<n;i++) { fflush(stdin); // <= do this or cin.ignore(); cout<<"\nEnter Book Name : "; cin.getline(b[i].bookname,20); ................ ...............
5th Jul 2020, 4:10 PM
rodwynnejones
rodwynnejones - avatar
+ 1
cin.ignore() is works correctly. But fflush(stdin) is not working and that's says error .why? what is fflush and cin.ignore explain please.
6th Jul 2020, 9:00 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar