map::clear

清除映射的所有元素。

void clear( );

示例

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

// map_clear.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main()
{
    using namespace std;
    map<int, int> m1;
    map<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    m1.insert(Int_Pair(1, 1));
    m1.insert(Int_Pair(2, 4));

    i = m1.size();
    cout << "The size of the map is initially "
         << i << "." << endl;

    m1.clear();
    i = m1.size();
    cout << "The size of the map after clearing is "
         << i << "." << endl;
}
  
  

要求

标头: <map>

命名空间: std

请参见

参考

map Class

map::max_size, map::clear, map::erase, 和 map::size

标准模板库