Robust Input
//Demonstrates the function read_and_clean.
void read_and_clean(int& n);
//Reads a line of input. Discards all symbols except the digits.
//Converts the cstring to an integer and sets n equal to the
//Discards all the input remaining on the current input line.
//Also discards the '\n' at the end of the line.
cout << "Enter an integer and press return: ";
cout << "That string converts to the integer " << n << endl;
cout << "Again? (yes/no): ";
} while ( (ans != 'n') && (ans != 'N') );
void read_and_clean(int& n)
const int ARRAY_SIZE = 6;
char digit_string[ARRAY_SIZE];
if ( (isdigit(next)) && (index < ARRAY_SIZE - 1) )
digit_string[index] = next;
digit_string[index] = '\0';
} while (symbol != '\n');