set C++容器

时间:2014-12-19 00:23:08   收藏:0   阅读:188

1.如何判断set加入的值是否重复

    // 举例如下:
    int a[] = {1,2,3,4,5,6,7,8,1,2};
    int nSize = sizeof(a)/sizeof(a[0]);
    using namespace std;
    set<int> sint;
    for(int i=0; i<nSize; ++i)
    {
        pair<set<int>::iterator,bool> result = sint.insert(i);
        if(result.second == false) // 插入的值重复,返回false
        {
            // do something
        }
    }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!