您的位置: 首页 > IT文章 > set-max_size set-max_size 分类: IT文章 • 2024-01-05 09:17:18 //////////////////////////////////////// // 2018/04/29 8:14:44 // set-max_size // the maximun number of elements that the set can hold #include <iostream> #include <set> #include <algorithm> #include <iterator> using namespace std; void print(set<int, less<int>> s){ copy(s.begin(),s.end(), ostream_iterator<int>(cout, " ")); cout << endl; } //============================= int main(){ int ary[] = { 1, 2, 3, 2, 3, 4, 8, 2, 5, 6 }; set<int, less<int>> s; s.insert(ary, ary + 10); print(s); cout << "size of 's' = " << s.size() << endl; cout << "max_size of 's' = " << s.max_size() << endl; return 0; } /* OUTPUT: 1 2 3 4 5 6 8 size of 's' = 7 max_size of 's' = 214748364 */