0

cin.ignore

Can someone explain to me how to use cin.ignore ? thank youu

4th Dec 2018, 7:36 AM
Syed Bob
2 Answers
0
how to know how much we need to put in the cin.ignore ? for example :- char name[55]; int id; int main (){ cout<<" Enter your name : "; cin.getline(name,54); cout<<" Enter your ID : "; cin>>id; cout<<" Your name is : "<<name<<endl; cout<<" Your ID is : "<<id; return 0; } if I don't put cin.ignore, the output for ' Your ID is :' will be short and if I put cin.ignore like this :- char name[55]; int id; int main (){ cout<<" Enter your name : "; cin.ignore(24,'\n'); cin.getline(name,54); cout<<" Enter your ID : "; cin>>id; cout<<" Your name is : "<<name<<endl; cout<<" Your ID is : "<<id; return 0; } the output will be much worse, both name and id are wrong can someone explain to me please ?
4th Dec 2018, 3:20 PM
Syed Bob