100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > C++中Set的使用

C++中Set的使用

时间:2023-04-05 18:51:27

相关推荐

C++中Set的使用

/*#include <string> // 使用 string 类时须包含这个文件#include <iostream> // 这个就加上去吧。c++的输入和输出。using namespace std; //这个不能忘记了String 类的输入和输出要用cin和cout,否则就爆栈错了*/#include <iostream>#include <set>#include <string>using namespace std;set<string> ::iterator it;void print(set<string> iset){for (it = iset.begin();it != iset.end();it++){cout << *it;}}//函数还是能包装的。set也可以当做参数传入int main(){set<string> iset;iset.insert("1");iset.insert("2");iset.insert("3");/* 两种遍历set<string> ::iterator it;for (it = iset.begin();it != iset.end();it++){cout << *it;}set<string> ::reverse_iterator rit;for (rit = iset.rbegin();rit != iset.rend();rit++){cout << *rit;}迭代器和函数一一对应的。iterator -> begin endreverse_iterator -> rbegin rend*//*貌似只能删除键值。iset.erase("2");print(iset);*//* 返回的是迭代器。it = iset.find("1");cout << *it;*/}

my own code

It's beyond my imagination,the Iterator appears in the C++!

In my view,the Iterator only appears int the Java.(I'm so shortsighted)

there isn't any doubt that the Iterator is a powerful tool to traverse Collection.

just as you see,you can easily use a simple circle to implement traversal.

There is another point worth mentioning,the function "find" return Iterator.

according to my experience.the Iterator is actually a point.

you can try to output the value of Iterator.Which is always obeyond the range of Integer.

It appears more evident that using the '*' to get theactual value of the Iterator.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。