The example in this post is from C++ Primer Plus (6th Edition) by Stephen Prata
My question: Why cin.ignore( ) is not used in his example? Shouldn't we discard the buffer with a line similliar to this:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Example from the book:
int fill_array(double ar[], int limit)
{
using namespace std;
double temp;
int i;
for (i = 0; i < limit; i++)
{
cout << "Enter value #" << (i + 1) << ": ";
cin >> temp;
if (!cin) // bad input
{
cin.clear();
while (cin.get() != '\n')
continue;
cout << "Bad input; input process terminated.\n";
Functions and Arrays 327
break;
}
else if (temp < 0) // signal to terminate
break;
ar[i] = temp;
}
return i;
}