这里是基本vector操作;
```cpp
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a[3] = { 2,4,7 };
vector<int> n(2,6);
n.push_back(3);
n.insert(n.begin()+2,7);
n.insert(n.begin()+1,a, a + 2);
vector<int>::iterator it = n.begin();
for (; it != n.end(); ++it)
{
cout << *it << " ";
}
cout << n.front()<<" "<<n.back()<<" "<<n[2];
for (int i = 0; i < 5; i++)
cout << n[i] << " ";
vector<int> m = n;
vector<int>::iterator its = m.begin();
// cout << its;
for (; its != m.end(); its++)
cout << *its << " ";
return 0;
}
```下面是结果
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20191214214611164.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1OTUzMzMz,size_16,color_FFFFFF,t_70)
初学者一起进步;
vector 初学者基本编程
最新推荐文章于 2024-07-25 20:22:48 发布