今天百度搜索了set容器迭代器的知识,不多说,直接贴代码:
#include <iostream>
#include <set>
using namespace std;
int main(int argc, const char * argv[]) {
set<string> set1;
string s1,s2,s3,s4;
s1 = "s1";
s2 = "s2";
s3 = "s3";
s4 = "s4";
set1.insert(s1);
set1.insert(s2);
set1.insert(s3);
set1.insert(s4);
for(set<string>::iterator it = set1.begin(); it != set1.end(); it++){
cout << *it << endl;
}
return 0;
}
其他容器的迭代器也是如此:
vector<类名>::iterator 迭代器名字;