This article mainly introduces how to set up sequential containers. I hope you will learn patiently.
#include#include #include #include #include //各种顺序容器的常见操作 //vector list dequeusing namespace std;int main() { vector
a; const vector ca;//常迭代器 list b; deque c; a.push_back(10); a.push_back(20); a.push_back(30); b.push_back(100); b.push_back(200); b.push_back(300); c.push_back(1); c.push_back(2); c.push_back(3); for (vector ::size_type i = 0; i < a.size(); ++i) //int可能不够大,可能超过i的范围 { cout << a[i] << endl; } ////list链表没有下标 //for (list ::size_type k = 0; k < b.size(); ++k) //{ // cout << b[k] << endl; //} for (deque ::size_type n = 0; n < c.size(); ++n) { cout << c[n] << endl; } vector ::iterator first = a.begin(); vector ::iterator last = a.end(); while (first != last) { cout << "迭代器循环" << endl; cout << *first << endl; ++first; } vector ::const_iterator cfirsta = ca.begin();//const不能push_back 数据 vector ::reverse_iterator rfirsta = a.rbegin();//逆序迭代器 vector ::reverse_iterator rlastra = a.rend();//从最后一个倒着向前 vector ::size_type a1; vector ::iterator a2;//迭代器 vector ::const_iterator a3;//常迭代器 vector ::reverse_iterator a4;//逆序迭代器,从最后一个元素向前迭代 vector ::const_reverse_iterator a5;//常逆序迭代器 vector ::difference_type a6;//容器中两个数据之间的距离 vector ::value_type a7; //vector ::reference a8; //引用,引用必须初始化 //vector ::const_reference a9;//常引用 list ::size_type b1; list ::iterator b2; list ::const_iterator b3; list ::reverse_iterator b4; list ::const_reverse_iterator b5; list ::difference_type b6; /*list ::reference b7;*/ //如上,deque同上 system("pause"); return 0; }
Related recommendations:
cocos2dx template container is simple to use (Vector, Map, Value)
php realizes reading the memory sequence number, php Reading memory sequence
The above is the detailed content of How to set up a sequential container. For more information, please follow other related articles on the PHP Chinese website!