在vs2013中,c++中set容器定义对象时,参数列表中显式调用greater无法被识别,什么原因?
#include<iostream>#include<algorithm>#include<set>#include<iterator>usingnamespacestd...
#include<iostream>
#include<algorithm>
#include<set>
#include<iterator>
using namespace std;
using std::greater;
template <class T>
void print_set(const T&s, const char *sr)
{
ostream_iterator<T::value_type>out(cout," ");
cout << sr;
copy(s.begin(),s.end(),out);
cout << endl;
}
int main()
{
typedef set<int>Se;
Se s1;
pair<Se::const_iterator, bool>p1;
for (int i = 3; i > 0; i--)
{
p1 = s1.insert(i);
if (p1.second)
{
cout << *(p1.first) << " true" << endl;
}
}
p1 = s1.insert(2);
if (p1.second)
{
cout << *(p1.first) << " true" << endl;
}
else
cout << "eorror" << endl;
print_set(s1, "s1:");
cout << "-----------------------" << endl;
typedef set<double, greater<int>>Sd;
Sd s2;
for (int i = 0; i < 3; i++)
{
s2.insert(i*0.3);
print_set(s2,"s2:");
}
if (s2.find(1.5) != s2.end())
{
cout << "存在1.5这个数" << endl;
}
if (s2.find(3.5) == s2.end())
{
cout << "不存在3.5这个数" << endl;
}
cout << "-----------------------" << endl;
getchar();
} 展开
#include<algorithm>
#include<set>
#include<iterator>
using namespace std;
using std::greater;
template <class T>
void print_set(const T&s, const char *sr)
{
ostream_iterator<T::value_type>out(cout," ");
cout << sr;
copy(s.begin(),s.end(),out);
cout << endl;
}
int main()
{
typedef set<int>Se;
Se s1;
pair<Se::const_iterator, bool>p1;
for (int i = 3; i > 0; i--)
{
p1 = s1.insert(i);
if (p1.second)
{
cout << *(p1.first) << " true" << endl;
}
}
p1 = s1.insert(2);
if (p1.second)
{
cout << *(p1.first) << " true" << endl;
}
else
cout << "eorror" << endl;
print_set(s1, "s1:");
cout << "-----------------------" << endl;
typedef set<double, greater<int>>Sd;
Sd s2;
for (int i = 0; i < 3; i++)
{
s2.insert(i*0.3);
print_set(s2,"s2:");
}
if (s2.find(1.5) != s2.end())
{
cout << "存在1.5这个数" << endl;
}
if (s2.find(3.5) == s2.end())
{
cout << "不存在3.5这个数" << endl;
}
cout << "-----------------------" << endl;
getchar();
} 展开
2个回答
2015-04-06
展开全部
包含头文件#include<functional>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询