Restrict user to input real number only in C++

前端 未结 10 1916
旧时难觅i
旧时难觅i 2021-01-15 06:40

How can I restrict the user to input real numbers only in C++ program?

Example:

double number; cin >> number;

and it won\'t accept t

10条回答
  •  被撕碎了的回忆
    2021-01-15 07:25

    You can retrieve your data as a std::string then use one of the standard string conversion function to see if the content matches your expectations.

提交回复
热议问题