set容器

1、基本用法

begin()    ,返回set容器的第一个元素

end()      ,返回set容器的最后一个元素

clear()    ,删除set容器中的所有的元素

empty()    ,判断set容器是否为空

max_size()   ,返回set容器可能包含的元素最大个数

size()      ,返回当前set容器中的元素个数

rbegin     ,返回的值和end()相同

rend()     ,返回的值和rbegin()相同

2.遍历

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

int main()
{
    set<int> s;
    for (int i = 0; i != 10; ++i) 
    s.insert(i);
    for (set::const_iterator p = s.cbegin(); p != s.cend(); ++p)
        cout << *p << " ";
    cout << "\n";

    return 0;
}

猜你喜欢

转载自blog.csdn.net/newproblems/article/details/78515400