set-size

////////////////////////////////////////
//      2018/04/29 8:43:56
//      set-size

// the number of elements in the set
#include <iostream>
#include <set>

using namespace std;

void print(set<int, less<int>> & s){
    set<int, less<int>>::iterator it;
    for (it = s.begin(); it != s.end(); it++){
        cout << *it << " ";
    }
    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);
    cout << "Size of set s = " << s.size() << endl;
    print(s);

    s.clear();
    cout << "Size of set s = " << s.size() << endl;

    return 0;
}

/*
OUTPUT:
    Size of set s = 7
    1 2 3 4 5 6 8
    Size of set s = 0
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12537894.html