vector的操作

//关于元素存取的函数
//operator[] 既重载[]使其类似于数组元素的操纵,实现随机访问
cout<<test.at(1)<<endl;//类似于[]的作用,只是是一个函数行形式
cout<<test.front()<<endl;//显示存在的第一个元素
cout<<test.back()<<endl;//显示存在的最后一个元素
int* p = test.data();//取到了一个指向顺序表的一个指针
cout<<test.front()<<endl;//显示存在的第一个元素

//修改动作函数
test.assign(arr,arr+3);//assign替换函数可以替换一个对象的区间或者一个同类型的数组
test.push_back(4);//尾插,并没有头插
test.pop_back();//尾删 
test.insert(it,5);//插入指定位置
test.erase(it);//删除指定位置
test.swap(test1);//交换函数,将两个对象进行交换
test.clear();//清空整个顺序表
vector<int>::iterator it2=test.emplace(it,5);//类似于insert但是会返回新插入元的迭代器
test.emplace_back(10);//类似于尾插

原创转载请注明出处