If a stream can't parse the wanted input to the variable, it will set an internal fail flag.
This flag can be checked by using the stream in a condition.
And the extraction operator returns a reference to the stream.
Put together you can do something like
while (s >> x)
{
// String starts with a number...
s.clear(); // Clear fail state flag
// TODO: Ask for new input, set contents of s
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…