How to validate numeric input C++

后端 未结 7 1976
忘了有多久
忘了有多久 2020-11-29 11:26

I\'d like to know how to limit an input value to signed decimals using std::cin.

7条回答
  •  既然无缘
    2020-11-29 12:22

    Something like:

    double a;
    cin >> a;
    

    Should read your signed "decimal" fine.

    You'll need a loop and some code to make sure it handles invalid input in a sensible way.

    Good luck!

提交回复
热议问题