I\'d like to know how to limit an input value to signed decimals using std::cin
.
cin's >> operator works by reading one character at a time until it hits whitespace. That will slurp the whole string -1a2.0
, which is obviously not a number so the operation fails. It looks like you actually have three fields there, -1, a, and 2.0. If you separate the data by whitespace, cin will be able to read each one without problem. Just remember to read a char
for the second field.