hash_map::size

备注

此 API 已过时。替代为 unordered_map 类

返回中元素的数目。hash_map 的。

size_type size( ) const;

返回值

当前 hash_map 的长度。

备注

在Visual C++ .NET 2003中,成员<hash_map><hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间

示例

在编译此示例与 /Wp64 标志或在 64 位平台时,编译器将生成警告 C4267。 有关该警告的更多信息,请参见 编译器警告(等级 3)C4267

// hash_map_size.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
    using namespace std;
    using namespace stdext;
    hash_map<int, int> hm1, hm2;
    hash_map<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    hm1.insert(Int_Pair(1, 1));
    i = hm1.size();
    cout << "The hash_map length is " << i << "." << endl;

    hm1.insert(Int_Pair(2, 4));
    i = hm1.size();
    cout << "The hash_map length is now " << i << "." << endl;
}
  

要求

标头: <hash_map>

**命名空间:**stdext

请参见

参考

hash_map 类

标准模板库