set 函数

初始化一个

set<int> st = {8, 2, 3, 4, 5, 5, 5, 5};

创建迭代器

这样会很方便的创建 让auto 自己去判断

    auto t = st.begin();
    t++;

erase

3种用法 比较有趣

	//erase 1. 两个参数 删除这两个迭代器之间的数
    st.erase(t, st.end());
    //erase 2.删除迭代器t的数
    st.erase(t);
    //erase 3.删除数字n 并返回删除的个数 (0或1<吐血>)
    st.erase(2);

count

    //count 返回n的数量 其实就只返回0或1吧
    cout << st.count(5);

find

返回是迭代器 找不到返回 st.end();

    t = st.find(5);
    if (t == st.end())
        ;

输出

    for (auto x : st)
       cout << x << ' ';

好吧 我承认了 我懒(其实不想花时间搞这个)
本来就想把这几个不怎么常用的记到文件里的
但…还是放到CSDN
有几个特别常用的我没写
分享一个网站 感觉很友好 不是深 可以看懂 里面都介绍了

传送门

发布了106 篇原创文章 · 获赞 25 · 访问量 7224

猜你喜欢

转载自blog.csdn.net/weixin_45653525/article/details/104197275