首页 文章资讯内容详情

C ++ STL中的multiset size()示例

2026-06-05 1 花语

在本教程中,我们将讨论一个程序,以了解C++STL中的multisetsize()。

函数size()返回给定容器中存在的元素数。

示例

#include <bits/stdc++.h> using namespace std; int main(){ multiset<int> s; s.insert(10); s.insert(13); cout << "The size of multiset: " << s.size(); s.insert(13); s.insert(25); cout << "\nThe size of multiset: " << s.size(); s.insert(24); cout << "\nThe size of multiset: " << s.size(); return 0; }

输出结果

The size of multiset: 2 The size of multiset: 4 The size of multiset: 5