iterator 指向第一個數字 1 , 儘管插入"0" ,讓這集合變成{0,1,4,6,9,10}
iterator 依舊是指向1,要注意唷~
- #include <iostream>
- #include <set>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int str[] = {1,4,6,9,10};
- set<int> a(str, str+5);
- set<int>::iterator p = a.begin(); //現在迭代器是指向1
- //插入0以後,變成 {0,1,4,6,9,10},迭代器仍指向1
- a.insert(0);
- cout << *++p << endl;
- copy(a.begin(), a.end(),ostream_iterator<int, char> (cout, " ")) ;
- }
沒有留言:
張貼留言