问题与返回的在C++中布尔..C++返回boolean值95
bool find(const TrieNode &node, const string word)
{
if (word.length() == 0)
{
if (node.isWord)
{
cout << "TRUE" << endl;
return true;
}
else
{
cout << "FALSE" << endl;
return false;
}
}
char firstletter = word.at(0);
int index = firstletter - 'a';
if (node.letters[index] == NULL)
{
return false;
}
else
{
find (*node.letters[index],word.substr(1,(word.length() - 1)));
}
}
在
我主我
cout << find(*mynode,"word") << endl;
会屈服于:
FALSE
显然,a cout of FALSE意味着该函数返回false ..但是,当我打印出函数的结果时,我得到95的结果为true。任何理由为什么它可以这样做?
感谢
好奇,虽然该流插入运算符实际打印95,这可能意味着不存在“布尔“插入,它只是投给一个int? – 2011-06-17 06:38:53
@ edA-qa:它可能被扩展/提升为int,但在大多数(x86)系统中,“bool”是一个字节,它使它成为一个数字并且不局限于1/0。 – Necrolis 2011-06-17 07:14:39
很明显,一个明显的错误(C中的未定义行为,C++中的非法行为)编译时没有警告,除非明确要求它。除了最大警告级别之外,不能编译的另一个很好的理由。 – Damon 2011-06-17 07:47:24