当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ multiset size()用法及代码示例


multiset::size()是C++ STL中的内置函数,该函数返回多集容器中的元素数。

用法:

multiset_name.size()

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


返回值:该函数返回多重集容器中的元素数。

以下示例程序旨在说明上述函数:

程序1:

// CPP program to demonstrate the 
// multiset::size() function 
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
  
    multiset<int> s; 
  
    // Function to insert elements 
    // in the multiset container 
    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

程序2:

// CPP program to demonstrate the 
// multiset::size() function 
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
  
    multiset<int> s; 
  
    cout << "The size of multiset:" << s.size(); 
    s.insert(2); 
    s.insert(3); 
  
    cout << "\nThe size of multiset:" << s.size(); 
    s.insert(4); 
  
    cout << "\nThe size of multiset:" << s.size(); 
    return 0; 
}
输出:
The size of multiset:0
The size of multiset:2
The size of multiset:3

std::multiset的所有函数



相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 multiset size() in C++ STL with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。