#include <iostream>
#include<set>
#include<functional>
#include<iterator>
using namespace std;
int main()
{
int arry1[] = { 3,3,6,7,6,1,3,2,3,2 };
set<int> s1;
set<int,greater<int> >s2;//由于greater<>是个函数,降序,所以要加这个头文件#include<functional>,
for(size_t i = 0; i < sizeof(ary)/sizeof(int); ++i)
{
s1.insert(arry1[i]);
s2.insert(arry1[i]);
}
set<int>::iterator It = s1.begin();
std::cout<<"s1:";
while(It != s1.end())
{
std::cout<<*It++<<" ";
}
std::cout<<std::endl;
It = s2.begin();
std::cout<<"s2 : ";
while(It != s2.end())
{
std::cout<<*It++<<" ";
}
return 0;
}
VS2012中要加入#incude<functional>才能通过编译,但是在Code::Blocks编译器中,不用加#include<functional>也能运行。如果哪位朋友知道原因,可以指导我一下,谢谢