find函数有很多个。有些可以,有些不可以。
(1)string类里的find函数。此函数的原型有四个:
size_t find (const string& str, size_t pos = 0) const noexcept;
size_t find (const char* s, size_t pos = 0) const;
size_t find (const char* s, size_t pos, size_type n) const;
size_t find (char c, size_t pos = 0) const noexcept;
均返回size_t,因此可以与0比较。与-1比较的话会导致-1转换为无符号整型而变成一个非常大的数。
(2)(unordered_)(multi)set/map类里的find函数,或algorithm头文件里的find函数。这些find函数返回相应的迭代器,因此不能与-1或0比较。
?
哪个find ????
如果是 STL的.
一般是 map 和 Hash_map
iter = obj.find(key);
if (iter != obj.end())
{
// find 有内容 do something
}
STL 用迭代器判断 , 没印象用 -1 . 0 返回值判断...
CString 中find返回的就是int型的,可以比较,如果是自己写的就要看类型,其它类要看比较符是否有重载,如果有重载就能比较。
可以的,只要类型相同。
应该可以。