谁知道在C++模板库中或是STL中的set(集合)的用法?先谢谢了

icecore 2000-08-31 09:28:00
...全文
204 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tomorrow 2000-11-28
  • 打赏
  • 举报
回复
MSDN里有很多例子的

#pragma warning(disable:4786)
#include <set>
#include <iostream>

using namespace std ;

typedef set<int> SET_INT;

void main() {
SET_INT s1;
SET_INT::iterator i;
cout << "s1.insert(5)" << endl;
s1.insert(5);
cout << "s1.insert(10)" << endl;
s1.insert(10);
cout << "s1.insert(15)" << endl;
s1.insert(15);
cout << "s1.insert(20)" << endl;
s1.insert(20);
cout << "s1.insert(25)" << endl;
s1.insert(25);

cout << "s1 -- starting at s1.lower_bound(12)" << endl;
// prints: 15,20,25
for (i=s1.lower_bound(12);i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;

cout << "s1 -- starting at s1.lower_bound(15)" << endl;
// prints: 15,20,25
for (i=s1.lower_bound(15);i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;

cout << "s1 -- starting at s1.upper_bound(12)" << endl;
// prints: 15,20,25
for (i=s1.upper_bound(12);i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;

cout << "s1 -- starting at s1.upper_bound(15)" << endl;
// prints: 20,25
for (i=s1.upper_bound(15);i!=s1.end();i++)
cout << "s1 has " << *i << " in its set." << endl;

cout << "s1 -- s1.equal_range(12)" << endl;
// does not print anything
for (i=s1.equal_range(12).first;i!=s1.equal_range(12).second;i++)
cout << "s1 has " << *i << " in its set." << endl;

cout << "s1 -- s1.equal_range(15)" << endl;
// prints: 15
for (i=s1.equal_range(15).first;i!=s1.equal_range(15).second;i++)
cout << "s1 has " << *i << " in its set." << endl;
}

icecore 2000-09-01
  • 打赏
  • 举报
回复
各位,我找的了STL的E文文档。
不过,太多了。
有哪位朋友有关于set的中文文档么?或是知道现在市面上有STL的书(中文的哦)卖么?
望告知啊。
若是没有的话,我只好去看E文文档了。

wangjue28 2000-08-31
  • 打赏
  • 举报
回复
关注。

69,337

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧