#include <iostream>
#include <limits> //numeric_limits
int main()
{
int Size;
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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzPiAvL251bWVyaWNfbGltaXRzCgppbnQgbWFpbigpCnsKCWludCBTaXplOwoJY2hhciBjOwoJc3RkOjpjb3V0IDw8ICJQbGVhc2UgZW50ZXIgYW4gaW50ZWdlcjogIjsKCXdoaWxlKCAhKHN0ZDo6Y2luID4+IFNpemUpIHx8ICggc3RkOjpjaW4uZ2V0KGMpICYmIGMgIT0gJ1xuJyApICkKCXsKCQlzdGQ6OmNpbi5jbGVhcigpOyAvL2NsZWFyIGVycm9yIGZsYWdzCgkJc3RkOjpjaW4uaWdub3JlKCBzdGQ6Om51bWVyaWNfbGltaXRzPHN0ZDo6c3RyZWFtc2l6ZT46Om1heCgpICwgJ1xuJyApOyAvL2lnbm9yZSBhbnl0aGluZyBsZWZ0CgkJLy9zdGQ6OmNpbi5pZ25vcmUoIDEwMjQgLCAnXG4nICkgb3IgYW55dGhpbmcgbGFyZ2Ugd2lsbCB3b3JrIHRvbwogICAgCXN0ZDo6Y291dCA8PCAiSW52YWxpZCBpbnB1dC4gUGxlYXNlIHRyeSBhZ2FpbihpbnRlZ2VyIG9ubHkpOiAiOwoJfQoKCXN0ZDo6Y291dCA8PCAiVGhlIHZhbGlkIGludGVnZXIgZW50ZXJlZCB3YXM6ICIgPDwgU2l6ZSA8PCBzdGQ6OmVuZGw7Cn0=