我的 ctype.h 中有函数 isnumber()。我在http://www.cplusplus.com/reference/cctype/中也没有的书籍中找不到此功能的参考资料以供参考。我打算通过一个简单的例子来检测并显示 isdigit() 和 isnumber() 之间的区别,但没有(此外,函数无法检测到 U+0C6A、U+0ED2 和 ½)。有什么区别吗?我该如何解决?
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;
}
结果的一部分:
...
5 numbers,
5 digits,
23 graphs,
2 spaces
in Hello½123, Poly౪ ໒girl0.5!!!