As the name itself suggests, cin.ignore()
is used when you want to ignore one or more input buffer characters.
What is the exact time to use cin.ignore () in software written in C ++?
The cin.ignore()
treats as the delimiter the characters: \t
and \n
, then you will use when you receive an entry and you want to ignore those characters that remained in the input buffer .
So, what's the right way to use cin.ignore ()?
In summary, you use cases that you want to ignore unread characters in the input buffer , as I mentioned earlier.
Ex:
You want to get a string
of the user and store in a char
:
char teste[20];
Read the entry using cin
:
cin >> teste;
Assuming the user entered teste
and pressed ENTER. The teste
will be received, and \n
will remain in the input buffer.
I tried to be as brief as possible in the answer, this reference can be a complement to your understanding.