begin函数
语法:
1 |
iterator begin() const; |
begin()返回指向第一个元素的迭代器
源代码
1 2 3 4 5 6 7 |
/** * Returns a read/write iterator that points to the first element in the * %set. Iteration is done in ascending order according to the keys. */ iterator begin() const { return _M_t.begin(); } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <set> using namespace std; int main() { set<int> s1; s1.insert(10); s1.insert(12); s1.insert(13); s1.insert(9); cout<<"s1集合中元素数量:"<<s1.size()<<endl; set<int>::iterator iter = s1.begin(); for(iter;iter!=s1.end();iter++){ cout<<*iter<<" "; } cout<<endl; } |
测试结果:
1 2 |
s1集合中元素数量:4 9 10 12 13 |