C++ STL set用法

#include<iostream>
#include<set>
using namespace std;

set<int>::iterator iter;
set<int> s;
int main(){
    // insert some elements
    s.insert(1);
    s.insert(3);
    s.insert(6);
    s.insert(8);

    // travese all elements
    for(iter = s.begin(); iter!=s.end(); iter++){
        cout << *iter << " ";
    }
    cout << endl;

    // find the element
    iter = s.find(1);
    if(iter != s.end()){
        cout  << "found" << endl;
    }else{
        cout  << "not found" << endl;
    }

    //remove all elements
    s.clear();

    cout << s.size() << endl;
}

猜你喜欢

转载自blog.csdn.net/m0_37550202/article/details/88543449
今日推荐