There are numerous ways to do this but here is one method:
Loop while 1) it fails to read into an integer or 2) there is anything left in the buffer other than the newline left from std::cin >>
1 2 3 4 5 6 7 8 9 10 11
char c;
std::cout << "Please enter an integer: ";
while( !(std::cin >> Size) || ( std::cin.get(c) && c != '\n' )
{
std::cin.clear(); //clear error flags
std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n' ); //ignore anything left
//std::cin.ignore( 1024 , '\n' ) or anything large will work too
std::cout << "Invalid input. Please try again(integer only): ";
}
std::cout << "The valid integer entered was: " << Size << std::endl;