cin.clear() clears all error flags that may be set on cin (that may be caused by a previous input operation failing, or something the like). That shouldn't be there, if an error did occur somewhere it should be handled there, not just randomly discarded in the next input operation.
cin.ignore(cin.rdbuf()->in_avail()) discards all characters that may be left over from previous input operations.