Sort of
cin >> Delay1;
if(cin) { ... }
, cin . Enter. - .
3a
double, a, . cin a . , , . , , - , .
, , getline,
string delay;
if(!getline(std::cin, delay) || !isnumber(delay)) {
...
}
isnumber
bool isnumber(string const &str) {
std::istringstream ss(str);
double d;
return (ss >> d) && (ss >> std::ws).eof();
}
operator>> , std::ws . , eof. , , , cin.
, double double `isnumber, .
, operator void*, operator!, good(), fail(), bad() eof(), :
flag | badbit | failbit | eofbit
function | | |
-----------------+---------+-----------+--------
op void* | x | x |
-----------------+---------+-----------+--------
op ! | x | x |
-----------------+---------+-----------+--------
good() | x | x | x
-----------------+---------+-----------+--------
fail() | x | x |
-----------------+---------+-----------+--------
bad() | x | |
-----------------+---------+-----------+--------
eof() | | | x
-----------------+---------+-----------+--------
x, . operator void* bool (if(cin) ...), operator! , !cin