Why we use cin.ignore() ? Can anyone tell me about this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why we use cin.ignore() ? Can anyone tell me about this?

I wanna know about this because someone ask me about this but i don't know the reason behind this

3rd May 2018, 5:30 PM
Nouman Bin Sami
Nouman Bin Sami - avatar
6 Answers
+ 3
cin.ignore() basically discards n number of characters or until the delimiting character has been found. For example the statement "cin.ignore(10, 'J');" will ignore the first 10 characters (specified by the first parameter) or until the character "J" is found (specified by the second parameter). Both of these parameters are optional and will default to 1 (first parameter) and EOF (second parameter).
3rd May 2018, 8:45 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 3
So, we use ignore function to ignore the chars until user enter a specific char to go ahead the next statement
17th Jun 2018, 8:01 AM
Nouman Bin Sami
Nouman Bin Sami - avatar
+ 2
Yes
17th Jun 2018, 12:47 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 2
thanks 😊
17th Jun 2018, 12:49 PM
Nouman Bin Sami
Nouman Bin Sami - avatar
+ 1
For example the statement "cin.ignore(10, 'J');" will ignore the first 10 characters (specified by the first parameter) or until the character "J" is found (specified by the second parameter). Both of these parameters are optional and will default to 1 (first parameter) and EOF (second parameter). " I'm sorry, but can you explain more detail about ' ignore the first 10 characters ' ?
4th Dec 2018, 3:31 PM
Syed Bob
0
and also about the second parameter
4th Dec 2018, 3:32 PM
Syed Bob