1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <iostream>
#include <forward_list> using namespace std;
template <class T> void Print(T begin, T end) { for (T p = begin; p != end; ++p) { cout << *p << " "; } cout << endl; }
int main() { forward_list<int> l3(5, 111); cout << "第一个元素值:" << *l3.begin() << endl;
cout << typeid(forward_list<int>::iterator::iterator_category).name() << endl;
forward_list<int>::iterator it = l3.begin();
*(++it) = 222; *(++it) = 333; *(++it) = 444; *(++it) = 555;
++it; cout << "是否指向最后一个的下一个: " << (it == l3.end()) << endl;
forward_list<int>::const_iterator it2 = l3.cbegin();
for (forward_list<int>::iterator it = l3.begin(); it != l3.end(); ++it) { cout << *it << " "; } cout << endl;
Print<forward_list<int>::iterator>(l3.begin(), l3.end()); return 0;
}
|