作者:jicanmeng
时间:2017年06月21日
Sequence Containers的两个例子:
vector的用法:
#include <iostream> #include <vector> int main() { using namespace std; vector<int> vect; for (int nCount=0; nCount < 6; nCount++) vect.push_back(10 - nCount); // insert at end of array for (int nIndex=0; nIndex < vect.size(); nIndex++) cout << vect[nIndex] << " "; cout << endl; }
以下是运行结果:
[jicanmeng@andy tmp]$ ./a.out
10 9 8 7 6 5
[jicanmeng@andy tmp]$
deque的用法:
#include <iostream> #include <deque> int main() { using namespace std; deque<int> deq; for (int nCount=0; nCount < 3; nCount++) { deq.push_back(nCount); // insert at end of array deq.push_front(10 - nCount); // insert at front of array } for (int nIndex=0; nIndex < deq.size(); nIndex++) cout << deq[nIndex] << " "; cout << endl; }
以下是运行结果:
[jicanmeng@andy tmp]$ ./a.out
8 9 10 0 1 2
[jicanmeng@andy tmp]$