vector是我使用比较多的一个容器,它相当于一个动态的数组,在STL中给他提供了很多接口,简单易懂,接下来简单的演示一下它是如何使用的。
我一般使用的一些函数接口有size(),reserve(),empty(),begin(),end(),push_back(),find(),erase()。
使用vector一般都会用到迭代器iterator,它是在STL中数据结构与算法的桥梁。它相当于一个指针,用来指向vector中的元素。
vector<int>::iterator it;
1 #include2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 int main() 9 {10 vector ivec;11 vector ::const_iterator it=ivec.begin();12 ivec.reserve(10); 13 cout< <