hash_map::size (STL/CLR)

计算元素的数量。

    size_type size();

备注

成员函数返回控制序列的函数。 使用其当前确定元素的数目。控制序列。 如果您关注的是序列是否具有非零大小,请参见 hash_map::empty (STL/CLR)()。

示例

// cliext_hash_map_size.cpp 
// compile with: /clr 
#include <cliext/hash_map> 
 
typedef cliext::hash_map<wchar_t, int> Myhash_map; 
int main() 
    { 
    Myhash_map c1; 
    c1.insert(Myhash_map::make_value(L'a', 1)); 
    c1.insert(Myhash_map::make_value(L'b', 2)); 
    c1.insert(Myhash_map::make_value(L'c', 3)); 
 
// display contents " [a 1] [b 2] [c 3]" 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// clear the container and reinspect 
    c1.clear(); 
    System::Console::WriteLine("size() = {0} after clearing", c1.size()); 
 
// add elements and clear again 
    c1.insert(Myhash_map::make_value(L'd', 4)); 
    c1.insert(Myhash_map::make_value(L'e', 5)); 
    System::Console::WriteLine("size() = {0} after adding 2", c1.size()); 
    return (0); 
    } 
 
  

要求

标头: <cliext/hash_map>

命名空间: cliext

请参见

参考

hash_map (STL/CLR)

hash_map::empty (STL/CLR)