题解 | #迭代器遍历set#

迭代器遍历set

https://www.nowcoder.com/practice/7e57c0f7af86429db20c70053f23ea96

  • 迭代器iterator正向遍历set集合元素
#include

using namespace std;

int main(){
    sets;
    // write your code here......
    for (int i = 0; i < 5; i++) {
        int temp = 0;
        cin >> temp;
        //插入元素在set集合中
        s.insert(temp);
    }

    //开始遍历
    for (set::iterator it = s.begin(); it != s.end(); it++) {
        cout << *it << " ";
    }

    return 0;
}
全部评论

相关推荐

02-22 21:16
已编辑
门头沟学院 运营
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务