This code suppose to accept numbers only and numbers must be exactly 12 numbers. The first is working but the latter is not. User enter 13 numbers but no error is display.
std::string line;
double d;
while (std::getline(std::cin, line))
{
std::stringstream ss(line);
if (ss >> d || line.size() == 12)
{
if (ss.eof())
{ // Success
break;
}
}
std::cout << "Error!" << std::endl;
}
Please can somebody help me with this to get it work? Thanks in advance.
Try and instead of or: