C++ STL中的无序序多集清除()函数

这个 无序的多集::清除() 在C++ STL中是一个内置函数,它清除无序的多集容器的内容。函数调用后容器的最终大小为0。

null

语法:

unordered_multiset_name.clear()

参数: 该函数不接受任何参数。

返回值: 它什么也不返回。

以下程序说明了上述功能:

项目1:

// C++ program to illustrate the
// unordered_multiset::clear() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration
unordered_multiset< int > sample;
// inserts element
sample.insert(11);
sample.insert(11);
sample.insert(11);
sample.insert(12);
sample.insert(13);
sample.insert(13);
sample.insert(14);
cout << "Elements: " ;
for ( auto it = sample.begin(); it != sample.end(); it++) {
cout << *it << " " ;
}
sample.clear();
cout << "Size of container after function call: "
<< sample.size();
return 0;
}


输出:

Elements: 14 11 11 11 12 13 13 
Size of container after function call: 0

项目2:

// C++ program to illustrate the
// unordered_multiset::clear() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration
unordered_multiset< int > sample;
// inserts element
sample.insert(1);
sample.insert(1);
sample.insert(1);
sample.insert(2);
sample.insert(3);
sample.insert(4);
sample.insert(3);
cout << "Elements: " ;
for ( auto it = sample.begin(); it != sample.end(); it++) {
cout << *it << " " ;
}
sample.clear();
cout << "Size of container after function call: "
<< sample.size();
return 0;
}


输出:

Elements: 1 1 1 2 3 3 4 
Size of container after function call: 0

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享