I have the function isnumber() in my ctype.h. I don’t find references of this function in the books I have neither in http://www.cplusplus.com/reference/cctype/ for consult. I intend to detect and show the difference between isdigit() and isnumber() by a simple example, but there is not (besides, U+0C6A, U+0ED2 and ½ are undetectable by the functions). Is there any difference? How could I resolve that?
int main(int, char *[])
{
string text("Hello½123, Poly౪ ໒girl0.5!!!");
decltype(text.size()) punct = 0, alpha = 0, number = 0, space = 0, digit = 0, graf = 0;
for(auto i : text) {
if(ispunct(i)){
cout << i << "<punct ";
++punct;
}
if(isalpha(i)) {
cout << i << "<alpha ";
++alpha;
}
if(isnumber(i)) {
cout << i << "<number ";
++number;
}
if(isdigit(i)) {
cout << i << "<digit ";
++digit;
}
if(isgraph(i)) {
cout << i << "<graph ";
++graf;
}
if(isspace(i))
++space;
}
cout << endl << "There is " << endl;
cout << punct << " puncts," << endl;
cout << alpha << " alphas," << endl;
cout << number << " numbers," << endl;
cout << digit << " digits," << endl;
cout << graf << " graphs," << endl;
cout << space << " spaces" << endl;
cout << "in " << text << endl;
return 0;
}
A part of the result:
...
5 numbers,
5 digits,
23 graphs,
2 spaces
in Hello½123, Poly౪ ໒girl0.5!!!
isnumber()
may be an Apple-specific C++ method (I don't have a Mac on hand to check).
You can see it in the Apple dev guide:
The
isnumber()
function behaves similarly toisdigit()
, but may recognize additional characters, depending on the current locale setting.
Besides, isnumber()
is not declared on Linux:
I use g++ 6.1.1 on Linux 4.7.2 and get the error:
g++ a.cpp
a.cpp: In function 'int main(int, char**)':
a.cpp:20:17: error: 'isnumber' was not declared in this scope
if (isnumber(i)) {
^
I also use clang3.8.1 to test:
clang++ a.cpp --std=c++11
a.cpp:20:7: error: use of undeclared identifier 'isnumber'
if (isnumber(i)) {
^