it mess up the cin >> statment by going pass the statement
if \n is on the buffer, cin.ignore() get it off the buffer so as not
to affect the other cin >> statments.
Code:
#include <iostream>
using namespace std;
int main()
{
char a, b, c;
cin >> a;
cin >> b;
cin >> c;
cout << a << " " << b << " " << c << endl;
cin.get();
}
compared to this
Code:
#include <iostream>
using namespace std;
int main()
{
char a, b, c;
cout << "letter : ";
cin >> a;
cin.ignore(80, '\n');
cout << "letter : ";
cin >> b;
cin.ignore(80, '\n');
cout << "letter : ";
cin >> c;
cin.ignore(80, '\n');
cout << a << " " << b << " " << c << endl;
cin.get();
}
if you try to enter more character then a, b, or c, can hold
then ignore removes them off the buffer so not to affect
the other cin >> statments.
id say it was good coding practice, to handle all possibly mistake
by the user, so it may not have been a priority here, but
shoudl still be something to consider.