這段代碼有問題,但是我找不到導致它的原因。C++比較表達式錯誤
bool Parser::validateName(std::string name) {
int pos = name.find(INVALID_CHARS); //pos is -1,
bool result = ((name.find(INVALID_CHARS)) < 0); //result is false
//That was weird, does that imply that -1 >= 0?, let's see
result = (pos < 0) //result is true
result = ((name.find(INVALID_CHARS)) == -1) //result is true
result = (-1 < 0) //result is true
...
}
爲什麼結果在第二行是錯誤的。有沒有我沒有看到的東西?
我懷疑這一點。你可以在ideone上發佈可運行的代碼嗎? –
請注意,另外在'INVALID_CHARS'中使用複數形式會讓人懷疑這是否是一個充滿無效字符的字符串,並且您是否不想要類似'find_first_of'的東西。 – PlasmaHH
返回find的類型是size_t。 – Chubsdad