字符串temp等于我的调试器中的"ZERO:\ t.WORD\t1".(我文件的第一行)
string temp = RemoveWhiteSpace(data);
int i = 0;
if ( temp.length() > 0 && isalpha(temp[0]) )
cout << "without true worked" << endl;
if ( temp.length() > 0 && isalpha(temp[0]) == true )
cout << "with true worked" << endl;
Run Code Online (Sandbox Code Playgroud)
这是我的代码,用于检查temp的第一个字符是否为az,AZ.第一个if语句将评估为true,第二个将评估为false.为什么?!?!?!即使没有"temp.length()> 0 &&",我也试过这个,但它仍然评估为false.它只是讨厌"== true".我唯一能想到的是isalpha()返回!= 0和true == 1.然后,你可以得到isalpha()== 2!= 1.但是,我不知道C++是不是......奇怪的.
顺便说一句,我不需要知道"== true"在逻辑上毫无意义.我知道.
输出是
without true worked
Run Code Online (Sandbox Code Playgroud)
在Ubuntu 9.10上使用GNU GCC编译CodeBlock(如果这很重要)
如果为true,则*函数仅保证返回非零值,不一定是1.典型的实现是基于表的,表中的每个字符值都有一个条目,一组位定义哪个位意味着什么.is*函数将只是与表值一起使用右边的位掩码,并返回该值,对于位位置0给出的任何类型,它只是值1.
例如:
#define __digit 1
#define __lower 2
#define __upper 4
extern int __type_table[];
int isdigit(int c) {
return __type_table[c+1] & __digit;
}
int isalpha(int c) {
return __type_table[c+1] & (__lower | __upper);
}
int islower(int c) {
return __type_table[c+1] & __lower;
}
int isupper(int c) {
return __type_table[c+1] & __upper;
}
Run Code Online (Sandbox Code Playgroud)
在哪里__type_table被定义为类似的int __type_table[UINT_MAX+1];并且将被初始化(例如)__type_table['0'+1] == __digit和__type_table['A'+1] == __upper.
如果你关心,'+1'部分是在表的开头留一个点EOF(通常定义为-1).