藉助示例理解 C++ STL 中的 multiset max_size()


在本文中,我們將討論一個程式,它幫助理解 C++ STL 中的 multiset max_size()。

函式 max_size() 返回一個給定容器可以容納的最大元素數。

示例

 線上演示

#include <bits/stdc++.h>
using namespace std;
int main(){
   multiset<int> s;
   s.insert(10);
   s.insert(13);
   s.insert(13);
   s.insert(25);
   s.insert(24);
   cout << "The multiset elements are: ";
   for (auto it = s.begin(); it != s.end(); it++)
      cout << *it << " ";
   cout << "\nThe max size of multiset: " << s.max_size();
   return 0;
}

輸出

The multiset elements are: 10 13 13 24 25
The max size of multiset: 461168601842738790

更新時間:2020 年 4 月 6 日

84 次瀏覽

啟動您的職業

完成課程以獲得認證

開始
廣告
© . All rights reserved.