hash_set::find

说明说明

此 API 已过时。另一种方法是 unordered_set Class

返回解决的迭代器一个元素的位置在具有键等效于指定的键的 hash_set 的。

iterator find(
   const Key& _Key
);
const_iterator find(
   const Key& _Key
) const;

参数

  • _Key
    一个元素的排序关键字将匹配的参数键从要搜索的 hash_set 的。

返回值

解决元素设置为与指定的键或解决成功最后一个元素的位置。hash_set 的 迭代器const_iterator,如果与未作为项中。

备注

成员函数返回解决在 hash_set 的元素排序关键字是 equivalent 给参数键在二进制谓词下生成基于的排序小于可比性关系的迭代器。

如果 查找 的返回值赋给 const_iterator,不能修改 hash_set 对象。如果 查找 的返回值赋给 迭代器,可以修改 hash_set 对象。

在 Visual C++ .NET 2003 中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间

示例

// hash_set_find.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_set <int> hs1;
   hash_set <int> :: const_iterator hs1_AcIter, hs1_RcIter;
   
   hs1.insert( 10 );
   hs1.insert( 20 );
   hs1.insert( 30 );

   hs1_RcIter = hs1.find( 20 );
   cout << "The element of hash_set hs1 with a key of 20 is: "
        << *hs1_RcIter << "." << endl;

   hs1_RcIter = hs1.find( 40 );

   // If no match is found for the key, end( ) is returned
   if ( hs1_RcIter == hs1.end( ) )
      cout << "The hash_set hs1 doesn't have an element "
           << "with a key of 40." << endl;
   else
      cout << "The element of hash_set hs1 with a key of 40 is: "
           << *hs1_RcIter << "." << endl;

   // The element at a specific ___location in the hash_set can be found 
   // by using a dereferenced iterator addressing the ___location
   hs1_AcIter = hs1.end( );
   hs1_AcIter--;
   hs1_RcIter = hs1.find( *hs1_AcIter );
   cout << "The element of hs1 with a key matching "
        << "that of the last element is: "
        << *hs1_RcIter << "." << endl;
}
  
  
  

要求

标头: <hash_set>

命名空间: stdext

请参见

参考

hash_set Class

标准模板库