map::find (STL/CLR)
尋找符合指定之索引鍵的項目。
iterator find(key_type key);
參數
- Key - 索引鍵
要搜尋的索引值。
備註
如果在受控制序列的至少一個項目具有與 key相等的定序,成員函式來傳回指定項目之一的 Iterator;否則會傳回 map::end (STL/CLR)()。 您可以使用它目前設定項目符合指定索引鍵的控制順序。
範例
// cliext_map_find.cpp
// compile with: /clr
#include <cliext/map>
typedef cliext::map<wchar_t, int> Mymap;
int main()
{
Mymap c1;
c1.insert(Mymap::make_value(L'a', 1));
c1.insert(Mymap::make_value(L'b', 2));
c1.insert(Mymap::make_value(L'c', 3));
// display contents " [a 1] [b 2] [c 3]"
for each (Mymap::value_type elem in c1)
System::Console::Write(" [{0} {1}]", elem->first, elem->second);
System::Console::WriteLine();
System::Console::WriteLine("find {0} = {1}",
L'A', c1.find(L'A') != c1.end());
Mymap::iterator it = c1.find(L'b');
System::Console::WriteLine("find {0} = [{1} {2}]",
L'b', it->first, it->second);
System::Console::WriteLine("find {0} = {1}",
L'C', c1.find(L'C') != c1.end());
return (0);
}
說明
需留意到 find 無法保證哪幾個項目找到。
需求
標頭: <cliext/map>
命名空間: cliext