Know What The Input Data Is Whether Integer Or Not

[Solved] Know What The Input Data Is Whether Integer Or Not | Vb - Code Explorer | yomemimo.com
Question : know what the input data is whether integer or not

Answered by : nutty-narwhal-h6c82q4b9ghy

#include <iostream>
using std::cout;
using std::cin;
using std::endl
using std::string;
bool isNumber(const string& str)
{ for (char const &c : str) { if (std::isdigit(c) == 0) return false; } return true;
}
int main(){ string str1 = "231524randstr23"; string str2 = "23152423"; string str3 = "a3152423"; isNumber(str1) ? cout << "Number\n" : cout << "Not number\n"; isNumber(str2) ? cout << "Number\n" : cout << "Not number\n"; isNumber(str3) ? cout << "Number\n" : cout << "Not number\n"; return EXIT_SUCCESS;
}

Source : https://www.delftstack.com/howto/cpp/how-to-determine-if-a-string-is-number-cpp/ | Last Update : Thu, 30 Dec 21

Answers related to know what the input data is whether integer or not

Code Explorer Popular Question For Vb