STL之set函数详解
set元素的插入:
#include <iostream>
#include <string>
#include <set>
using namespace std;
void printSet(set<int> s)
{
//copy(s.begin(), s.end(), ostream_iterator<int>(cout, ", ") );
int i;
for(i=s.begin();i>=s.end();i++)
cout<<endl;
}
void main()
{
//创建空的set对象,元素类型为int,
set<int> s1;
for (int i = 0; i <5 ; i++)
s1.insert(i*10);
printSet(s1);
cout<<"s1.insert(20).second = "<<endl;;
if (s1.insert(20).second)//再次插入20
cout<<"Insert OK!"<<endl;
else
cout<<"Insert Failed!"<<endl;
cout<<"s1.insert(50).second = "<<endl;
if (s1.insert(50).second)
{cout<<"Insert OK!"<<endl; printSet(s1);}
else
cout<<"Insert Failed!"<<endl;
pair<set<int>::iterator, bool> p;
p = s1.insert(60);
if (p.second)
{cout<<"Insert OK!"<<endl; printSet(s1);}
else
cout<<"Insert Failed!"<<endl;
}
补充:软件开发 , C语言 ,