c++ – What is the difference between isdigit() and isnumber()?

c++ – What is the difference between isdigit() and isnumber()?

isnumber() may be an Apple-specific C++ method (I dont have a Mac on hand to check).
You can see it in the Apple dev guide:

The isnumber() function behaves similarly to isdigit(), 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)) {
                    ^

isdigit() only works with 0-9.

isnumber() allows other number values such as fractions. Some characters that are numeric but not digits include 0x00b2 and 0x00b3 which are superscripted 2 and 3 (² and ³) and the glyphs that are fractions such as ¼, ½, and ¾.

c++ – What is the difference between isdigit() and isnumber()?

The isnumber() function was added by Apple, so you need to use Apple documentation.

Heres a quote from the ctype.h manpage for iOS:

STANDARDS
     These functions, except for digittoint(), isascii(), ishexnumber(),
     isideogram(), isnumber(), isphonogram(), isrune(), isspecial() and
     toascii(), conform to ISO/IEC 9899:1990 (``ISO C90).

The same page doesnt actually link to a manpage for isnumber(), but I extrapolated its URL from the links to manpages for the standard functions, and found this:

The isnumber() function behaves similarly to isdigit(), but may recognize
additional characters, depending on the current locale setting.

Result #4 on Google for isnumber ctype

Leave a Reply

Your email address will not be published.