【C、C++】ctype.h、cctype中的isnumber()函数和isdigit()函数的区别

栏目: C++ · 发布时间: 7年前

内容简介:isnumber()函数和isdigit()函数并无区别,查看函数定义发现也是相同的,可能有微小的区别,也就是说:isnumber()函数与isdigit()相似,但isnumber()可能会识别其他字符,具体取决于当前的区域设置~

isnumber()函数和isdigit()函数并无区别,查看函数定义发现也是相同的,可能有微小的区别, Mac OS X 手册页 上ctype函数中对isnumber()和isdigit()函数的区别是这样解释的:

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

也就是说:isnumber()函数与isdigit()相似,但isnumber()可能会识别其他字符,具体取决于当前的区域设置~

在XCode或者CLion(Mac版)的ctype.h(或者cctype)中可能会见到isnumber()函数,然而查阅C++官方文档却找不到,这是因为isnumber()并不是C/C++的官方库函数,而是Apple特地为Mac OS的C++添加的它认为好用的一些函数(这些函数有很多,不止isnumber)。可以查看 Mac OS X Man Pages中ctype函数页 找到isnumber()函数~手册中也提到isnumber()并不在C90标准中:

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

可以看到如果使用isnumber()函数在 Linux 环境下g++是无法编译通过的:

g++ a.cpp
a.cpp: In function 'int main()':
a.cpp:20:17: error: 'isnumber' was not declared in this scope
   if (isnumber(c)) {
                 ^

在Clang下也是无法编译通过的:

clang++ a.cpp --std=c++11
a.cpp:20:7: error: use of undeclared identifier 'isnumber'
                if (isnumber(c)) {
                    ^

所以isnumber()并不是标准的C/C++库函数,如果是刷算法的时候还是不要使用哦~

❤❤点击这里 -> 订阅PAT、蓝桥杯、GPLT天梯赛、LeetCode题解离线版❤❤ 【C、C++】ctype.h、cctype中的isnumber()函数和isdigit()函数的区别

以上所述就是小编给大家介绍的《【C、C++】ctype.h、cctype中的isnumber()函数和isdigit()函数的区别》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Java Message Service API Tutorial and Reference

Java Message Service API Tutorial and Reference

Hapner, Mark; Burridge, Rich; Sharma, Rahul / 2002-2 / $ 56.49

Java Message Service (JMS) represents a powerful solution for communicating between Java enterprise applications, software components, and legacy systems. In this authoritative tutorial and comprehens......一起来看看 《Java Message Service API Tutorial and Reference》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具