Determines whether the input number is decimal. Through a limited sample experiment, we can conclude that this procedure is still feasible.
# Include <iostream> # include <string> # include <sstream> using namespace std; bool isZero (string testNum, string: size_type index) {string testZero ('0 ', index); if (! TestNum. compare (index, (testNum. size ()-index), testZero) {return true;} else {return false;} bool isDecimal (string inputNum) {string: size_type decimalPointIndex = inputNum. find (". "); if (decimalPointIndex <= inputNum. size ()&&! IsZero (inputNum, decimalPointIndex) {return true;} else {return false;} int main (void) {double inputNumber; cin> inputNumber; stringstream ss; string strNum; ss <inputNumber; ss> strNum; bool flg = isDecimal (strNum); if (flg) {cout <"this is a decimal" <endl ;} else {cout <"This is not a decimal number" <endl;} return 0 ;}