try
{
int code = 0;
std::cout << "Please Enter 8 digit number: ";
std::cin >> code;
if (std::cin.bad()||std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Recieved code that is not an integer or convertable to an integer" << std::endl;
}
GTIN_8 gtin(code);
std::cout << gtin << std::endl;
system("pause");
}
catch (const std::exception& exception)
{
std::cout << exception.what() << std::endl;
}
catch (...)
{
std::cout << "An unknown error occurred, please try again" << std::endl;;
}
}
so Basically I've got this, it works fine when I enter something like aab or aa3
but when I enter something that starts with a number, like 1ab it passes the 1 to the function, which I don't want - I would like to completely ignore the imput and try again