#include <iostream>#include<vector>#include<algorithm>using namespacestd;intmain () {vector<int>VEC; Vec.push_back (1);//inserting elements at the tailVec.push_back (2);//cout<<vec[1];//access element by subscript, starting with [0] /*//using iterators to access elements vector<int>::iterator it; For (It=vec.begin (); It!=vec.end (); it++) cout<<*it<< ' \ t '; */Vec.insert (Vec.begin ()+1,3);//where to insert 3 into vec[1]vec.erase (Vec.begin ()+1);//Delete the vec[1]Vec.push_back (3); Vec.erase (Vec.begin ()+1, Vec.begin () +3);//delete the vec[1]-vec[2];cout<<vec.size () <<endl;//find the number of elements in a vector containerVec.clear ();//Empty the containerCout<<vec.empty ();//determine if the container is emptysort (Vec.begin (), Vec.end ());//to sort the VEC return 0;}
Common application of vector container in C++stl library