A
Alf P. Steinbach
* James Gregory:
Perhaps.
The program
#include <iostream>
#include <iomanip> // setw
#include <cctype> // is_digit
int main()
{
using namespace std;
for( int i = 0; i <= UCHAR_MAX; ++i )
{
if( isdigit( i ) )
{
cout << setw( 3 ) << i << setw( 2 ) << char(i) << endl;
}
}
}
compiled with g++ 3.2.3, fails to reproduce your problem, giving
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
Why don't you check _which_ values and what the corresponding chars are
in the characters set used (Windows specific note: use chcp command if
this is a console program). And post the code and results. Always a
good idea to post the code -- we're not telepaths, you know... ;-)
isdigit is not limited to ASCII.
What is the problem?
I read that the argument to isdigit() can be "an integer whose value is
representable as an unsigned char, or the value of the macro EOF.". This
seems to say that it should work for values greater than 127
Yes.
. And in
Linux + GCC, it does - values between 128 and 255 are false.
However, in Windows XP + GCC (at least some) values between 128 and 255
come out as true for isdigit. Someone suggested this may be because
Windows uses a different character set?
Perhaps.
The program
#include <iostream>
#include <iomanip> // setw
#include <cctype> // is_digit
int main()
{
using namespace std;
for( int i = 0; i <= UCHAR_MAX; ++i )
{
if( isdigit( i ) )
{
cout << setw( 3 ) << i << setw( 2 ) << char(i) << endl;
}
}
}
compiled with g++ 3.2.3, fails to reproduce your problem, giving
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
Why don't you check _which_ values and what the corresponding chars are
in the characters set used (Windows specific note: use chcp command if
this is a console program). And post the code and results. Always a
good idea to post the code -- we're not telepaths, you know... ;-)
So am I not supposed to use isdigit for non-ASCII values?
isdigit is not limited to ASCII.
What is the best alternative? Writing my own isdigit function?
What is the problem?