Wednesday, 15 January 2014

c++ - isdigit() is not working? -



c++ - isdigit() is not working? -

when come in number , test isdigit, returns false, why?

#include <iostream> using namespace std; int main() { int num; cin >> num; if(isdigit(num)) cout << "is number"; else cout << "that not number"; }

sample input: 1

that's because intent of isdigit check character whether or not it's ascii digit. instance:

if (isdigit('4')) { // yep }

or:

std::string str = "12345"; if (std::all_of(str.begin(), str.end(), isdigit)) { // ok safe int = std::stoi(str); }

it checking if input between '0' , '9'. say, 48 , 57. homecoming 0 other value.

c++ cin

No comments:

Post a Comment