共用方式為


hash_set::find

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_set Class

傳回位址的 Iterator 一個項目位置有索引鍵等於特定索引鍵 hash_set 的。

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

參數

  • _Key
    項目的排序鍵將符合的引數索引鍵從被搜尋的 hash_set 的。

傳回值

處理項目位置等於指定按鍵或解決成功最後一個項目位置或 const_iterator hash_set 的 iterator ,如果沒有符合為索引鍵中找到。

備註

解決 hash_set 的項目排序鍵是 equivalent 引數索引鍵在一個二進位述詞下會根據的順序小於可比性關聯的成員函式傳回 Iterator。

如果的傳回值指派給 const_iteratorfind ,無法修改 hash_set 物件。 如果傳回值 find 指派給 iterator,可以修改 hash_set 物件。

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 std 命名空間,,而是移至 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

標準樣板程式庫